필터 지우기
필터 지우기

Making A table and a plot from a for loop

조회 수: 6 (최근 30일)
Am Gill
Am Gill 2020년 11월 8일
댓글: Arshey Dhangekar 2021년 5월 29일
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.

채택된 답변

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 8일
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
Arshey Dhangekar
Arshey Dhangekar 2021년 5월 29일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by