Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
I'm playing around with selected elements of a vector, or array. Suppose I only want elements 2..6. Why does Mathcad fail when using a range for the index, but defining an index as a range does not? Curious.
Thanks in advance.
Solved! Go to Solution.
Mathcad doesn't fail, but simply wasn't designed to allow an immediate range in the index. So it gives an error message when you try.
You could consider to request this as a (new) feature. Maybe, someday, it might get implemented.
Until then: If you need a subset of a vector or array, use the submatrix() function. Look it up in the help.
Success!
Luc
Have you tried using the submatrix function?
Bob
Mathcad doesn't fail, but simply wasn't designed to allow an immediate range in the index. So it gives an error message when you try.
You could consider to request this as a (new) feature. Maybe, someday, it might get implemented.
Until then: If you need a subset of a vector or array, use the submatrix() function. Look it up in the help.
Success!
Luc
HI Luc,
Thanks for the comment. As you and RantEng mentioned, I did look up the submatrix function, but was trying to find a quicker way around it. It's just an intermediate step, I suppose.
Thank you.
Actually, while m[i (which you think is working) looks like a vector, it isn't! Its neither a vector, nor a range. Its an invalid Prime object and you can prove that by trying to assign it a variable - you get an error. So this method may be useful just to display part of the vector.
So to create a subvector, you have two options.
Either, as was already mentioned, you use the "submatrix" command or, if you really want to avoid this function, you actually can do it by using a range variable but you would have to do it the way shown in the picture below (v2).
Trying to avoid the definition of the range i on worksheet level by using an inline definition fails as Prime isn't written to accommodate that.
We can't define a range inline. In a program we would have to use a for-loop to achieve a similar effect
So my preference would be to use "submatrix" 🙂
If you have to use it more often in your sheet, it might be beneficial to write your own "subvec" function (in a collapsed area on top of the worksheet) to avoid to have to provide the two 0 columns all the time:
@Werner_E wrote:So my preference would be to use "submatrix" 🙂
I would have to agree! 😂
Thank you for the detailed explanation. I do appreciate it. Using Submatrix isn't all that much more difficult, as you said. So, I'll heed your suggestions and follow that method.
Regards,