Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Need Help using for and running a loop

1 vue (au cours des 30 derniers jours)
Matt
Matt le 9 Oct 2012
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (2)

the cyclist
the cyclist le 9 Oct 2012
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 commentaires
Matt
Matt le 9 Oct 2012
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 le 9 Oct 2012
Modifié(e) : per isakson le 9 Oct 2012
What does
K>> jhkmag{j}
and
K>> jhkmag{k}
show?

Walter Roberson
Walter Roberson le 9 Oct 2012
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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by