Effacer les filtres
Effacer les filtres

How can I overlap multiple lines on one plot in an iterative loop?

10 vues (au cours des 30 derniers jours)
Bobby DeCoursey
Bobby DeCoursey le 7 Juin 2021
Commenté : Bobby DeCoursey le 7 Juin 2021
Hello All,
I am having trouble overlapping multiple line graphs on the same axis. Currently, I am getting a graph for each iteration rather than a combination of all the graphs in one. An example of the code is shown below.
r = (1:10);
for i = 1:1:10
n = r(1,i);
t = num2str(n);
d = csvread(['data_',t,'.csv']);
p = d(:,3);
figure (), title ("Power");
plot(p,'g'),xlabel("Time"),ylabel("Power");
hold on
end
I have tried to store the values for each iteration, like this, but then I recieve error messages: "nonconformant arguments (op1 is 1x1, op2 is 1x4)".
r = (1:10);
for i = 1:1:10
n(i) = r(1,i);
t(i) = num2str(n(i));
...
end
Any help would be appreciated. Thanks in advance.

Réponse acceptée

Chunru
Chunru le 7 Juin 2021
Modifié(e) : Chunru le 7 Juin 2021
  • take the statement "figure()" just before the loop so that all plots are on the same figure
  • the plot command "plot(p, 'g') should better include variable t so that all plots have meaningful x-axis;
  • remove 'g' so that matlab cycle the default colors for each subsequent plot (if this is what you deire)

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by