repetitively running the code and selectively plotting

1 Ansicht (letzte 30 Tage)
uzzi
uzzi am 27 Okt. 2022
Kommentiert: uzzi am 1 Nov. 2022
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

Antworten (1)

Image Analyst
Image Analyst am 28 Okt. 2022
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 Kommentare
Image Analyst
Image Analyst am 30 Okt. 2022
How are you defnining a?
uzzi
uzzi am 1 Nov. 2022
"a" is a variable for the given table.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by