Making Multiple Plots Using a For Loop
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bob
el 14 de Dic. de 2014
Respondida: Image Analyst
el 14 de Dic. de 2014
I have the matrix A
A=[1 5 7 8; 4 3 2 3; 5 8 7 1]
For all of the plots, the x axis range is x=[1 2 3 4]
I need to have 3 plots total.
From matrix A, I have y1=[1 5 7 8], y2=[4 3 2 3], y3=[5 8 7 1]
I want to plot (x, y1), (x, y2), (x, y3)
How can I increment through the matrix using a for loop so that I can do something like plot(x(i),y(i)) and have all 3 of the plots made in a for loop?
This problem only has 3 plots, but I am going to need to a similar problem with several more plots so it would be really helpful if somebody could show me how to plot this using a for loop.
0 comentarios
Respuesta aceptada
Image Analyst
el 14 de Dic. de 2014
Try this:
% Create sample data.
x = 1:4;
numberOfRows = 9;
% A=[1 5 7 8; 4 3 2 3; 5 8 7 1]
A = randi(9, numberOfRows, 4)
[rows, columns] = size(A);
% Figure out array size for subplots.
numberOfPlotsInRow = ceil(sqrt(rows))
% Do the plotting.
for row = 1 : rows
% Figure out which place it needs to go into.
subplot(numberOfPlotsInRow, numberOfPlotsInRow, row);
% Do the plot.
plot(x, A(row, :), 'bs-', 'LineWidth', 2);
% Make it fancy.
grid on;
caption = sprintf('Row #%d', row);
title(caption, 'FontSize', 15);
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!