FOR loop calculating next values using the previous values
Show older comments
Hi there,
I have a pre-defined matrix 257 x 3 matrix, say Xin = [X Y Z]. Based on that, I would like to calculate a new matrix Xout = [M N P], using the values from Xin, such that e.g.:
M1 = (X2-X1) * sin(Y1*Z1) * cos(Y2*Z2)
M2 = (X3-X2) * cos(Y2*Z2) * sin (Y3*Z3)
and so on until the last value of 257.
So far I used the FOR loop (1:size(Xin,1)) and tried to pull the values from Xin using (i) and (i-1), however it states that "Subscript indices must either be real positive integers or logicals" that obviously happens when i=1.
I tried to overcome this by pre-defining X1,Y1,Z1 from Xin such e.g., X1 = Xin (1,1) and then start the FOR loop from (2:size(Xin,1)) but then it gives an error that index exceeds matrix dimensions.
X1,Y1,Z1 cannot initially be set up as some random values, since they come from the real survey data.
Any help would be appreciated. Thank you in advance!
2 Comments
Jan
on 7 Jan 2019
Please post your code. Then it is easy to suggest a modification.
John Pickles
on 7 Jan 2019
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!