Skip to main content
1-Visitor
January 20, 2016
Solved

Simple variable (range or vector) question

  • January 20, 2016
  • 3 replies
  • 2088 views

I'm having a problem figuring out how to do some math on a subset of a vector.  I have some data that I want to store in a variable (range or vector).  I want to be able to perform some simple math on portions of that variable, but it's not working the way I'd expect.

(I apologize, I don't know how to add mathcad notation in this forum)

Example.

I have 4 elements I'm storing in a variable called row (row = 1,3,7,15) using range variables ii=0..3

I want to take the 2nd through 4th element and subtract off the 1st through 3rd element and store that in a new variable which would have the result of newrow = 2,4,8

I thought I could just do the following

jj=1..3

kk = 0..2

newrow[kk = row[[jj - row[[kk

but I get an error saying jj should be an integer.

What am I missing?

Thanks!

Best answer by MJG

How about this?

3 replies

MJG1-VisitorAnswer
1-Visitor
January 20, 2016

How about this?

jwhitwam1-VisitorAuthor
1-Visitor
January 20, 2016

That looks like it's what I want to do.  Now the question is, why does it have to be done that way?  Why doesn't my way work as it looks to be doing basically the same thing?

23-Emerald IV
January 20, 2016

Another option is to use the submatrix function:

Luc

25-Diamond I
January 21, 2016

If you are not using the crippled Express version, you may also consider using a user defined function: