Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Need Help using for and running a loop
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
the cyclist
il 9 Ott 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 Commenti
per isakson
il 9 Ott 2012
Modificato: per isakson
il 9 Ott 2012
What does
K>> jhkmag{j}
and
K>> jhkmag{k}
show?
Walter Roberson
il 9 Ott 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.
0 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!