repetitively running the code and selectively plotting

1 visualización (últimos 30 días)
uzzi
uzzi el 27 de Oct. de 2022
Comentada: uzzi el 1 de Nov. de 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

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by