cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

comparing a scalar value to a array

YA_10963798
14-Alexandrite

comparing a scalar value to a array

Hi there,

I'm trying to compare a result I got as a array to one value .... if the condition is not meet the program should show error >>> it should compare each value in g... to explain it goes to the first row in g which contains a matrix (5*1) and compare the all the numbers in that matrix if it doesn't meet the conditon it writes error ... then goes to the second row in g and do the same 

YA_10963798_0-1732005982204.png

 

this is from the orginal sheet :

YA_10963798_1-1732005852008.png

 

Prime 10 is attached 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:YA_10963798)


@YA_10963798 wrote:

What I expect is option 3 :  a similar nested 5x1 vector as g but with values below 25 replaced by NaN, "error" . How did you do it 🙂


That way - the local function "replace" is called vectorized for every of the five vectors in g.

Werner_E_0-1732024364140.png

If you need that kind of check more often in the sheet and maybe with different conditions, it may be worth turning it into an appropriate function.

Werner_E_1-1732025664385.png

 

Prime 10 worksheet with all variants attached

 

View solution in original post

6 REPLIES 6

Here's one possibility:

Verife.png

 

 

YA_10963798
14-Alexandrite
(To:AlanStevens)

Can you tell me why did you put verife=0 in your function 

Werner_E
25-Diamond I
(To:YA_10963798)

So what do you expect as answer to your demo data set?

Is it the 25x1 vector which Alan shows or is it rather a 5x1 vector with all "error" because none of the five matrices in g consist of values which ALL are larger than 25?

Werner_E_1-1732013480413.png

 

Or, as a third possible interpretation which comes to my mind, do you expect a similar nested 5x1 vector as g but with values below 25 replaced by NaN, "error" or whatever?

 

So the options as I see it are

Werner_E_0-1732019915544.png

Werner_E_1-1732019943226.png

Werner_E_3-1732019967755.png

 

 

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

What I expect is option 3 :  a similar nested 5x1 vector as g but with values below 25 replaced by NaN, "error" . How did you do it 🙂

Werner_E
25-Diamond I
(To:YA_10963798)


@YA_10963798 wrote:

What I expect is option 3 :  a similar nested 5x1 vector as g but with values below 25 replaced by NaN, "error" . How did you do it 🙂


That way - the local function "replace" is called vectorized for every of the five vectors in g.

Werner_E_0-1732024364140.png

If you need that kind of check more often in the sheet and maybe with different conditions, it may be worth turning it into an appropriate function.

Werner_E_1-1732025664385.png

 

Prime 10 worksheet with all variants attached

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thank you so much Werner .... Really appreciate it 

Announcements

Top Tags