Dont know how to make a plot using for loop

so i have to create a plot that relates a set of variables against a time variable, but for that i need a for loop, because it has to go through multiple numbers, but i can code the for loop part.

댓글 수: 4

Voss
Voss 2022년 1월 20일
What do you have so far?
[pNN50_1]=time_domain_longRR(database1{1}.RR,L); %the function time_domain_longRR takes the parameter pNN50 that I want of a long period and stores tha in shorter terms in pNN50_1;
and know is my question, because i need to use that data I gathered and plot it agains a time variable
Voss
Voss 2022년 1월 21일
Can you share the code for time_domain_longRR? Or at least describe the input and output variables' classes and sizes? Where/what is the time variable you want to plot against, and what variables to you want to plot against it?
Hello,
Please share any code and relevant data so we can reproduce this issue at our end.
Thanks.

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

답변 (2개)

Benjamin Thompson
Benjamin Thompson 2022년 1월 25일

0 개 추천

It depends on how your time and data are stored, but you can always use the hold command to sequentially add plots in a for loop:
figure;
for (i = 1:10)
hold on;
plot(t, data(:,i));
hold off;
end
Soujanya Shimoga Raveendra
Soujanya Shimoga Raveendra 2022년 1월 28일

0 개 추천

As per my understanding, you wish to plot a set of variables against time axis.
Assuming 't' contains the time data and the gathered data pNN50_1 is a 1D array, you can directly plot as shown below:
figure
plot(t, pNN50_1);
If pNN50_1 is set of variables or a 2D array you can use either of the below methods:
figure
hold on
for i=1:length(t)
plot(t,pNN50_1(:,i)); %use plot(t,pNN50_1(i,:)); if data is present in rows
end
hold off
OR
figure
plot(t,pNN50_1); %the plot contains one line for each column in " pNN50_1”
% if data is present in rows, use plot(t,pNN50_1');
Refer to the below documentation for more information on “plot” function.
Hope this helps!

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2022년 1월 20일

답변:

2022년 1월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by