Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

YT
YT el 3 de Dic. de 2018
Editada: YT el 3 de Dic. de 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);

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by