Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hi.
I'm trying to output a vector based on a vector made by range variables. I'm not sure how to start this so any help is appreciated.
My input vector 5x1 and I want one output vector to give me a 3x1 one vector based on values in my vector which is bigger than value a and one output vector which is smaller than a. See attached for more info.
I can kind of solve it but I want the output vectors to be 3x1 and 2x1 vectors with no zeroes.
Thanks in advance!
Solved! Go to Solution.
Thank you, Alan!
That's perfect!
Some questions. Sorry if this should be obvious.
Can you explain the program step by step?
The things I'm wondering about are these:
1. Why start the program defining p as zero?
2. I'm not getting the grip with what is happening after the if statement with d3[p
Fredrik Jacobsen wrote:
Thank you, Alan!
That's perfect!
Some questions. Sorry if this should be obvious.
Can you explain the program step by step?
The things I'm wondering about are these:
1. Why start the program defining p as zero?
p is an index to positions in the vector d3 which will contain the items of d when d>a. Mathcad starts counting at zero, so I set it to zero to start. After it has been used it is incremented by 1. (You could start it at -1 and then, when you need to use it, increment it before assigning a value to that position in d3 etc.).
2. I'm not getting the grip with what is happening after the if statement with d3[p
Within the if statement there are two assignments. The first assigns the k'th value of d (corresponding to a non-zero value in d>a ) to the p'th position in d3. The second assignment then increments p by 1, ready for the next non-zero assignment to the next position in d3. p only increments when a non-zero value has been observed in d>a.
The final statement of the program simply returns the whole vector of values that have been stored in d3.
Alan
Here is a different way of achieving what you demandend, following your appraoch of using the vector of boolean values you calculated first. All you missed was trimming out the zeros which is what the built-in function trim() can do. trim() is part of an extension pack which usually is included in the normal Mathcad distribution but chances are that its not part of an educational license. If thats the case come back here for an alternative to trim().
That also worked nice, and very simple.
Thanks Werner!