Skip to main content
14-Alexandrite
October 27, 2024
Solved

Exclude some values

  • October 27, 2024
  • 1 reply
  • 10260 views

Hi there

I want to exclude some values from d when it is bigger than the width .... I want the program to just exclude the values that do not fulfil the condition, I used this program ,but it shows strange error ...I'm sure both of them have the same units 

YA_10963798_1-1730037766728.png

How to fix this ?

 

Best answer by Werner_E

You may also use a generic utility function to do the job:

Werner_E_0-1730044894764.png

You may then use either

Werner_E_2-1730041443456.png

or in one go

Werner_E_4-1730041480344.png

 

You have to decide what to return in case all elements have to be deleted. As Prime does not provide an empty array you may chose 0 or NaN or, like I did, a 1x1 array containing NaN (so I can still use the transpose operator even in that case).

 

 

Here some examples of usage

Werner_E_1-1730041177071.png

 

1 reply

25-Diamond I
October 27, 2024

Delete the word "rows", just use     if d[i < width

 

A simpler way probably would be to just use

Werner_E_7-1730042081725.png

or

Werner_E_8-1730042183264.png

Caution: This will fail, if ALL values in d are smaller than width or if ALL are larger or equal.

EDIT: See a more generic function which also deals with these special cases in my answer below.

 

 

 

Werner_E25-Diamond IAnswer
25-Diamond I
October 27, 2024

You may also use a generic utility function to do the job:

Werner_E_0-1730044894764.png

You may then use either

Werner_E_2-1730041443456.png

or in one go

Werner_E_4-1730041480344.png

 

You have to decide what to return in case all elements have to be deleted. As Prime does not provide an empty array you may chose 0 or NaN or, like I did, a 1x1 array containing NaN (so I can still use the transpose operator even in that case).

 

 

Here some examples of usage

Werner_E_1-1730041177071.png

 

23-Emerald V
October 27, 2024

Neat.

 

My preference is to return 0, as that way, it is clear that the result is not a vector and can be conveniently tested using a boolean. In addition, there are cases where [NaN] might be a valid (vector) result.

 

To deal with the transpose problem, I use a nifty transpose function, usually defined as T (in Constant Math Style), which transposes array inputs but leaves scalars alone.  

 

2024 10 27 A.png

 

I sometimes also use it (or suitable variants) under vectorization.  I have other variants for dealing with nested vectors when the display gets too tall or difficult to interpret.

 

Oddly, I also find it more keyboard-friendly, as typing "shift-T shift-9" comes to my fingers more readily than positioning the cursor where needed and typing "ctrl-shift-t," probably because it requires less hand movement.

 

Stuart