repetitively running the code and selectively plotting

조회 수: 2 (최근 30일)
uzzi
uzzi 2022년 10월 27일
댓글: uzzi 2022년 11월 1일
I am a new learner of Matlab and I am trying to learn to code with the loops. I am stucking with a problem.
I have table "a" which has multiple rows and 2 columns of table in matlab. I attached the file here.
1st column is time and 2nd column is data (q).
I want to make a loop for 6000 rows each and generate plot (data vs time). Before generating plots I want the user to see the starting time of each loop (the time from row 1,6001,12001) and let the user to decide the specific time to generate the specific plot related to that time.
I know my code is a lot of lacking and I am doing self learning. Can somebody help me out?
u = 1:1:6000 % I want to make it loop automatically from 1 to 100 but i don't know how
r = a.Time(u)
for i = 1:1:r
figure
plot
plot(a.t(i),a.q(i))
title(sprintf('Selling vs time from %s', ),r)
xlabel('time')
ylabel('selling $')
end

답변 (1개)

Image Analyst
Image Analyst 2022년 10월 28일
First use readmatrix or readtable to read in the data and plot the whole thing with a single call to plot. Then use input to ask the user what part they want to plot. Then in your loop you need to plot one marker and then call hold on
plot(a.t(i), a.q(i), 'b.', 'MarkerSize', 8);
hold on;
  댓글 수: 5
Image Analyst
Image Analyst 2022년 10월 30일
How are you defnining a?
uzzi
uzzi 2022년 11월 1일
"a" is a variable for the given table.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by