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

3 vues (au cours des 30 derniers jours)
Laurel Castillo
Laurel Castillo le 3 Déc 2018
Modifié(e) : YT le 3 Déc 2018
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.

Réponse acceptée

YT
YT le 3 Déc 2018
Modifié(e) : YT le 3 Déc 2018
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);

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by