Dont know how to make a plot using for loop
1 view (last 30 days)
Show older comments
Mara Pereira on 20 Jan 2022
Answered: Soujanya Shimoga Raveendra on 28 Jan 2022
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.
Soujanya Shimoga Raveendra on 25 Jan 2022
Please share any code and relevant data so we can reproduce this issue at our end.
Benjamin Thompson on 25 Jan 2022
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:
for (i = 1:10)
Soujanya Shimoga Raveendra on 28 Jan 2022
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:
If “pNN50_1” is set of variables or a 2D array you can use either of the below methods:
plot(t,pNN50_1(:,i)); %use plot(t,pNN50_1(i,:)); if data is present in rows
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!
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!