Plotting Matrix in Matlab Loop - Mathias

  • Context: MATLAB 
  • Thread starter Thread starter mathia
  • Start date Start date
  • Tags Tags
    Loop Matlab Plot
Click For Summary
SUMMARY

This discussion focuses on plotting multiple columns of a matrix in MATLAB using a loop. The user, Mathias, seeks to plot each column of matrix A against its first column with a single command. The solution involves using a for loop to iterate through the columns of A, specifically from 2 to 10, while employing the 'hold on' command to overlay the plots. Additionally, the user inquires about changing the color of each plot, which can be achieved by specifying color options within the plot command.

PREREQUISITES
  • Familiarity with MATLAB syntax and commands
  • Understanding of matrix indexing in MATLAB
  • Knowledge of plotting functions in MATLAB
  • Basic concepts of color specification in MATLAB plots
NEXT STEPS
  • Explore MATLAB's 'plot' function options for color customization
  • Learn about MATLAB's 'hold on' and 'hold off' commands for overlaying plots
  • Investigate advanced plotting techniques using MATLAB's 'subplot' function
  • Review MATLAB documentation on matrix operations and indexing
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers looking to visualize matrix data efficiently and customize plot appearances in their projects.

mathia
Messages
15
Reaction score
0
Hi,
I have a matrix for instance as follow:
A=[0.087 11.43 17.14 22.86 28.57 34.29 40.00 45.72 51.43 57.15
0.174 5.671 8.506 11.34 14.17 17.01 19.84 22.68 25.52 28.35
0.261 3.732 5.598 7.464 9.330 11.19 13.06 14.92 16.79 18.66
0.349 2.747 4.121 5.494 6.868 8.242 9.616 10.98 12.36 13.73
0.436 2.144 3.216 4.289 5.361 6.433 7.505 8.578 9.650 10.72
0.523 1.732 2.598 3.464 4.330 5.196 6.062 6.928 7.794 8.660];

I want to have all of this plot:
hold all
plot(A(:,1),A(:,2))
plot(A(:,1),A(:,3))
plot(A(:,1),A(:,4))
plot(A(:,1),A(:,5))
plot(A(:,1),A(:,6))
plot(A(:,1),A(:,7))
plot(A(:,1),A(:,8))
plot(A(:,1),A(:,9))
plot(A(:,1),A(:,10))

Can I have all of those plot just by using one plot command in a loop? If this is the case how can I do?
Thank you.
Best Regards,
Mathias
 
Physics news on Phys.org
are they separate plots?? if not overlaying them is accomplished by

Code:
for i = 2:10

plot(A(;,1),A(:,i));
hold on;

end
hold off;
 
thank you.
yes, they are separate plots.

can I change the color of each plot by using those commands?
for example I want plot(A(:,1),A(:,2)) be read, plot(A(:,1),A(:,3)) be green and so on.