Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Need Help using for and running a loop
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (2 件)
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 件のコメント
per isakson
2012 年 10 月 9 日
編集済み: per isakson
2012 年 10 月 9 日
What does
K>> jhkmag{j}
and
K>> jhkmag{k}
show?
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.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!