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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Translate the entire conversation x

Stack and sort a vector up to calculated z value

davidlimtw
8-Gravel

Stack and sort a vector up to calculated z value

Hi All,

 

What is the formula to stack the zcal into a vector and rearrange the vector up to the zcal value. Can anyone please advice?

 

davidlimtw_0-1740478635831.png

 

ACCEPTED SOLUTION

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

Why didn't you attach your worksheet?

 

Try

Werner_E_0-1740487392477.png

This approach will fail if no value in z.soil is larger than z.cal.

If this is a problem, you may use tray and catch to cope with it

Werner_E_1-1740487582490.png

 

Remarks

Now this approach would give a wrong result if ALL values in z.soil are larger than z.cal.

If z.cal is equal to a value in z.soil, this value will be seen twice at the end of the resulting vector - not sure if this is desired behaviour.

If the values in z.soil are not sorted, you should use sort(trim(....)).

 

Here is a version which also considers these points. I formulated it as function of z.cal because this makes testing all possible cases easier

Werner_E_3-1740489956616.png

 

 

 

 

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(To:davidlimtw)

Why didn't you attach your worksheet?

 

Try

Werner_E_0-1740487392477.png

This approach will fail if no value in z.soil is larger than z.cal.

If this is a problem, you may use tray and catch to cope with it

Werner_E_1-1740487582490.png

 

Remarks

Now this approach would give a wrong result if ALL values in z.soil are larger than z.cal.

If z.cal is equal to a value in z.soil, this value will be seen twice at the end of the resulting vector - not sure if this is desired behaviour.

If the values in z.soil are not sorted, you should use sort(trim(....)).

 

Here is a version which also considers these points. I formulated it as function of z.cal because this makes testing all possible cases easier

Werner_E_3-1740489956616.png

 

 

 

 

Werner_E
25-Diamond I
(To:Werner_E)

Here is a shorter approach which avoids Try and catch and deals with the 'special' cases with simple if-statements, which might be better readable and understandable.

Werner_E_0-1740494597105.png

 

Hi Werner,

 

Thanks for posting the solution. I found another solution in the forum from another user, I've done some modified in the loop and got the answer, Obviously your solution is better that captures the possibility of value more than the specified range. I will take your formula into my calculation. 

 

davidlimtw_0-1740494856803.png

 

Werner_E
25-Diamond I
(To:davidlimtw)


@davidlimtw wrote:

Hi Werner,

 

Thanks for posting the solution. I found another solution in the forum from another user, I've done some modified in the loop and got the answer, Obviously your solution is better that captures the possibility of value more than the specified range. I will take your formula into my calculation. 


It looks to me that your function also deals with values larger than the all values in the vector the very same way as mine.

Only difference is that in case you have a value which matches one of the value sin the vector, you will see it twice in the result.

Werner_E_0-1740496862725.png

If this is a problem, you may apply these modifications

Werner_E_1-1740497068326.png

Only difference to the variants I posted is now that in case z is smaller than all values in V  your result would be a vector with twice the value of z. In your case this would occur if you provide a negative value and I guess this would never be the case in your application.

 

E.g. set z.LP:=0,6 m and you will see this

Announcements

Top Tags