필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Need Help using for and running a loop

조회 수: 1 (최근 30일)
Matt
Matt 2012년 10월 9일
마감: MATLAB Answer Bot 2021년 8월 20일
Basically i have the following code;
for k = 1:357;
j = 357:1;
hold on
%%3D Elipsoid
%
x0 = jhkmag{k}(:,1)-jhkmag{j}(:,1);
hold on
y0 = dffmag{k}(:,1) - dffmag{j}(:,1);
hold on
z0 = dffmag{k}(:,2) - dffmag{j}(:,2);
rccm{k} = sqrt((0.5)*((x0{k}.^2)+(y0{k}.^2) + (z0{k}.^2)));
hold on
end
end
basically this code should calculate an ellipsoidal and calculate the distance to each point. But I cant get the loop to work it keeps saying that there is a bad cell reference, I really cant get this figured out. The next thing I need it to do is count to the nearest 15 data points, then compare that rccm on a different set of data results. I have no idea how to do this either pleeeeeaaase help

답변 (2개)

the cyclist
the cyclist 2012년 10월 9일
If you type
>> dbstop if error
before executing your code, then the code execution will halt when MATLAB hits the line causing the error, and you will be in debug mode. Then, you can go into the editor and see exactly what's happening, in terms of loop variable value, etc., to get more insight into the error.
After you track it down, you can type
>> dbclear if error
to disable the automatic stopping on error.
  댓글 수: 2
Matt
Matt 2012년 10월 9일
it says that its in the line starting with x0 this is what it says;
Bad cell reference operation.
Error in LoopGraphs (line 10) x0 = jhkmag{k}(:,1)-jhkmag{j}(:,1);
10 x0 = jhkmag{k}(:,1)-jhkmag{j}(:,1);
i still don't really understand why it wont do it though
per isakson
per isakson 2012년 10월 9일
편집: per isakson 2012년 10월 9일
What does
K>> jhkmag{j}
and
K>> jhkmag{k}
show?

Walter Roberson
Walter Roberson 2012년 10월 9일
j = 357:1; defines j as empty. If you want j to count down, use a negative increment,
j = 357:-1:1;
Also, the spacing you used,
for k = 1:357;
j = 357:1;
tends to give the impression that you are expecting the "for" to iterate both variables. A "for" loop only iterates a single variable. If you intend that j be assigned a vector in that statement, I recommend not indenting it to be aligned right under the "k =" of the line above.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by