Loop the Functions and store the values (placeholder) for Plotting

2 ビュー (過去 30 日間)
Laurel Castillo
Laurel Castillo 2018 年 12 月 3 日
編集済み: YT 2018 年 12 月 3 日
I want to run the main functions from t=0:0.1:10. And to store the results for plotting e.g. e VS t
Tried this:
......
for t=1:0.1:10
[q_kp1,e] = Inverse(psm_x,k, psm_J, q_k, t);
[psm_J, psm_x]=FKp(q_kp1);
plot(e)
hold on;
end
e.PNG
But when I try to plot(e,t) or plot(t,e). It shows nothing......
Here is the script:
%%% assign initial values for psm_J, psm_x, q_k_0, k, q_k, psm_x_dsr %%
psm_m = psm_q_initial();
[psm_J, psm_x, q_k_0]=pFK(psm_m.DH);
k=100;
q_k = q_k_0;
%%% main functions %%%
[q_kp1,e] = Inverse(psm_x,k, psm_J, q_k, t);
[psm_J, psm_x]=FKp(q_kp1);
Please help.

採用された回答

YT
YT 2018 年 12 月 3 日
編集済み: YT 2018 年 12 月 3 日
There are 2 ways to solve this
  1. Hold on and plot the result within the loop
figure();
hold on;
for t=1:0.1:10
[q_kp1,e] = Inverse(psm_x,k, psm_J, q_k, t);
[psm_J, psm_x]=FKp(q_kp1);
plot(t,e); %or plot(e,t) depends on what you want
end
hold off;
2. Save the values to an array and plot outside the loop
tV = [];%vector for t values
eV = [];%vector for e values
for t=1:0.1:10
[q_kp1,e] = Inverse(psm_x,k, psm_J, q_k, t);
[psm_J, psm_x]=FKp(q_kp1);
tV(end+1) = t;
eV(end+1) = e
end
figure();
plot(tV,eV);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by