Error - Index in position 1 is invalid. Array indices must be positive integers or logical values.
Ältere Kommentare anzeigen
I'm relatively new to coding and I was trying to apply a formula to a MATRIX to get relief angle.
Now A is a 10000 x 2 matrix and I want to apply the following formula to it, everytime I try to do so I recieve and Error "Index in position 1 is invalid. Array indices must be positive integers or logical values".
Error in Untitled (line 4)
Y=abs(atan((A(i-1,2)-A(i,2)/2000)));
A=Profiles(:,[1 2]);
for i = 1:10;
Y=abs(atan((A(i-1,2)-A(i,2)/2000)));
i=i+1;
end
Akzeptierte Antwort
Weitere Antworten (1)
Jakob B. Nielsen
am 16 Dez. 2019
The answer lies in the error - array indeces must be positive integers or logical values. That means you have an issue where its not.
You have this line:
for i = 1:10;
Y=abs(atan((A(i-1,2)-A(i,2)/2000)));
end
The first run will have i=1. That gives:
Y=abs(atan((A(1-1,2)-A(1,2)/2000)));
So you try to call A(0,2). What is the 0th row in a matrix? It doesnt exist, hence the error :)
You probably want to try to run your loop for i=2:10 instead.
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!