Azzera filtri
Azzera filtri

Making A table and a plot from a for loop

6 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Setsuna Yuuki.
Setsuna Yuuki. il 8 Nov 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 Commento
Arshey Dhangekar
Arshey Dhangekar il 29 Mag 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by