why this error ??

조회 수: 1 (최근 30일)
Kenza Boukallouch
Kenza Boukallouch 2020년 10월 16일
답변: Image Analyst 2020년 10월 16일
x=[-90 -90 -90 -90 -90 -45 -45 -45 -45 -45 0 0 0 0 0 45 45 45 45 45 90 90 90 90 90,45 22.5 0 -22.5 -45 45 22.5 0 -22.5 -45 45 22.5 0 -22.5 -45 45 22.5 0 -22.5 -45 45 22.5 0 -22.5 -45];
n=1;
when n<26;
f=0;
p=1/2*acosd(sqrt((1-sind(2*x(2,n))*sind(2*x(2,n)))/(1+tan(2*x(1,n))*tand(2*x(1,n)))));
ax=sqrt(1/(tand(p)*tand(p)+1));
ay= sqrt(1-ax^2);
d=acosd(tan(2*x(1,n))*sqrt((1-(sind(2*x(2,n))*sind(2*x(2,n))))/(tan(2*x(1,n))+((sind(2*x(2,n)))*(sind(2*x(2,n)))))));
f1=['simulation ',num2str(n)];
disp(f1);
f2=['ax=',num2str(ax),' ','ay=',num2str(ax),' ','d=',num2str(ax),' ','p=',num2str(p)];
disp(f2);
n = n+1;
end
Index in position 1 exceeds array bounds (must not exceed 1).

답변 (2개)

Alan Stevens
Alan Stevens 2020년 10월 16일
You have defined x as a 1x25 vector, but you are calling it with two arguments. You need to call it with x(n), rather than x(1,n) and x(2,n).
You probably also should use "while" rather than"when".

Image Analyst
Image Analyst 2020년 10월 16일
x has only one row, not two. So what value are you thinking of when you try to get the value in row 2, column n? Why do you think there should even be a x(2, n)???
Plus you must use while instead of when, or else just use a for loop
for n = 1 : 25

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by