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 CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by