Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hi there ,
I want to stack one value in a matrix in the correct order , but when I use stack function I can put it only in the beginning or at the end like this :
I want to put that -13.75 in the correct place which is in the middle in this case . How to use stack function and order the values in the same time
Thanks
Solved! Go to Solution.
Soup is nicely bubbling (eye of newt; goes nicely with the toasted bat-wing sandwiches), so ... time for one more method.
I added an extra test value to demonstrate that the order of the v & x values doesn't matter, just the indices. You could also write a program that does essentially the same thing.
Oh, forgot to mention, neither stack nor augment inserts values into an array; they just prepend or append values.
<Caveat>I haven't properly validated the results. You may wish to do so</Caveat>
Stuart
Try stack followed by sort. (followed by reverse, if necessary).
Can you explain more... BTW the value I want to insert may change depending on the input
Thanks
Here's one way, provided you want to add an element to the bottom, top, or middle of a vector.
There are other ways that more literally insert an element into a vector.
Stuart
I'd add another standard form (in Express, so no programming), but I've almost learned the dangers of trying to program or read whilst dinner is cooking on the hob!
Soup is nicely bubbling (eye of newt; goes nicely with the toasted bat-wing sandwiches), so ... time for one more method.
I added an extra test value to demonstrate that the order of the v & x values doesn't matter, just the indices. You could also write a program that does essentially the same thing.
Oh, forgot to mention, neither stack nor augment inserts values into an array; they just prepend or append values.
<Caveat>I haven't properly validated the results. You may wish to do so</Caveat>
Stuart
Thank you Stuart and I hope the soup was delicious.
You will have to be more specific as to what you are trying to achieve. Your screenshot shows a lot of variable names which we do not know the values of.
So I would suggest that you simplify it.
From what I understand you have a vector of values and this vector already is in descending order, right?
And all you want to do is to add a value to this vector and you want the new vector to be in descending order again. Is this correct?
Then what's your problem with Alan's suggestion??? Have you even tried to follow it?
Hi Werner,
I don't understand what Randy suggested this is why I asked for more clarification. Because sometimes my vector can have 10 values and the value I want to add may be in any order ( like the third of seventh) if I use reverse how can I guarantee that I will add the value in the accurate spot.
Thanks
Yusra
Hi Yusra,
Given that your z vector is depth-related, a natural assumption is that adding a new value should maintain depth-order. Hence, using my telepathic skills, Alan's suggesting the use of reverse after sorting. Which leads to a slightly more straightforward solution.
I wasn't sure whether you wanted to retain the depth order or needed to put a specific value at a particular index, hence the more general-purpose insertion suggestion.
Stuart
(The soup needed more garlic and less white pepper - the newts kept sneezing)
