Borrar filtros
Borrar filtros

Making A table and a plot from a for loop

6 visualizaciones (últimos 30 días)
Am Gill
Am Gill el 8 de Nov. de 2020
Comentada: Arshey Dhangekar el 29 de Mayo de 2021
Hi,
Using data collected from the for loop, I have been trying to create
1) One table with 4 columns (t, v, a, h) , and
2) 3 different graphs with t on the x axis for all 3 graphs, and v, a, h on the y axis of the respective graph (ie. plot(t,v), plot(t,a), plot(t,h)).
Here is my loop:
for t= 0:4:80
t
a= u*(q/(wt-q*t))-g
v= u*log((wt)./(wt-q*t))- g*t
h= u*t - u*(((wt./q)-t).*log((wt)./(wt-q*t)))-0.5*g*t.^2
end
Here are the values:
wt=2400+2000;
q =25;
u =12000;
g =32.2;
I have tried multiple ways such as putting my data from the loop to an array and then making a table and 3 graphs, etc. However, it failed as I can't seem to store each of the variable values into an array. How can I solve this problem? Or is there another way to make the table and plot?
Please help.

Respuesta aceptada

Setsuna Yuuki.
Setsuna Yuuki. el 8 de Nov. de 2020
wt=2400+2000;
q =25;
u =12000;
g =32.2;
largo = 100;
a = zeros(1,largo);
v = zeros(1,largo);
h = zeros(1,largo);
for t = 0:1:largo
a(t+1)= u*(q/(wt-q*t))-g;
v(t+1)= u*log((wt)./(wt-q*t))- g*t;
h(t+1)= u*t - u*(((wt./q)-t).*log((wt)./(wt-q*t)))-0.5*g*t.^2;
end
t = 0:1:largo;
%% plot
figure
plot(t,a,'LineWidth',2);hold on;
plot(t,v,'LineWidth',2);
plot(t,h,'LineWidth',2);
ylim([0 2e3]); xlabel('time') %limits Y, name x
legend('a(t)','v(t)','h(t)') %name of curves
%% table
t = t'; a=a'; v=v'; h=h';
vectores = table(t,a,v,h);
  1 comentario
Arshey Dhangekar
Arshey Dhangekar el 29 de Mayo de 2021
How can we use loop for ploting grpah for two columns?
I want to plot graph time vs every M varibale(in .csv file) with as subplot and combined plot for all columns present in table

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots 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