フィルターのクリア

Why is my For loop only using the last input number

2 ビュー (過去 30 日間)
Bryan
Bryan 2017 年 12 月 2 日
回答済み: Walter Roberson 2017 年 12 月 2 日
Hi I have a question on why my For loop is only using the last number (n = 7) and not using the values when n = 1-6. Below is my For Loop that is in my main script, and the actions of the For loop is part of my main function. The picture attached is the trajectory of each basketball shot; I'm suppose to be having 7 trajectories, but the For Loop only reads the last input. Please help and Thanks in advance.
for n = 1:7
[Xo, Yo, Zo, Imag, theta, phi, omgX, omgY, omgZ] = read_input('A.data',n);
[T, X, Y, Z, U, V, W] = basketball( Xo, Yo, Zo, Imag, theta, phi, omgX, omgY, omgZ);
end
figure(1); hold on;
plot3(X,Y,Z)

採用された回答

ANKUR KUMAR
ANKUR KUMAR 2017 年 12 月 2 日
Write the plot command inside the loop.
figure(1);
for n = 1:7
[Xo, Yo, Zo, Imag, theta, phi, omgX, omgY, omgZ] = read_input('A.data',n);
[T, X, Y, Z, U, V, W] = basketball( Xo, Yo, Zo, Imag, theta, phi, omgX, omgY, omgZ);
plot3(X,Y,Z)
hold on
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 2 日
clear X Y Z
for n = 1:7
[Xo, Yo, Zo, Imag, theta, phi, omgX, omgY, omgZ] = read_input('A.data',n);
[T, X(:,n), Y(:.n), Z(:,n), U, V, W] = basketball( Xo, Yo, Zo, Imag, theta, phi, omgX, omgY, omgZ);
end
Note: this code assumes that all of the trajectories have the same length for X, Y, and Z

カテゴリ

Help Center および File ExchangeDisplay Image についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by