How to Plot Multiple Matrices with Different Colors in Matlab?

  • Context: MATLAB 
  • Thread starter Thread starter Funzies
  • Start date Start date
  • Tags Tags
    Matlab Matrix Plot
Click For Summary
SUMMARY

This discussion focuses on plotting multiple matrices with different colors in MATLAB. The matrices are stored in a cell array, each being nx2 in size, where the first column represents x-coordinates and the second column represents y-coordinates. To achieve the desired plot, users should utilize the hold on; command and the plot function, specifically plot(matrix(1,:), matrix(2,:)) for each matrix. Additionally, users can refer to the MATLAB documentation for instructions on changing line colors.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of cell arrays in MATLAB
  • Knowledge of basic plotting functions in MATLAB
  • Ability to manipulate matrix data structures
NEXT STEPS
  • Explore MATLAB's hold on; functionality for multiple plots
  • Learn how to customize plot colors in MATLAB
  • Investigate the use of cell arrays for storing matrices in MATLAB
  • Study advanced plotting techniques in MATLAB, such as plot3 for 3D data
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers who need to visualize multiple datasets with distinct color coding in their plots.

Funzies
Messages
20
Reaction score
0
Hey guys, I'm having some trouble plotting a matrix.
I have a cell in which I've put four matrices. These matrices are variable in length: they are nx2 with n starting on 31 and varying from 0 to 120. De first column of each matrix represents the x-coordinate and the second column represents the y-coordinate from a point.
I want to plot these four matrices pointwise and fit lines through them, each having a different colour. Can anyone help me with this code? I can't seem to find the way in the Matlab help browser..
 
Physics news on Phys.org
For multiple plots, use
Code:
hold on;

To plot the matrices, for each matrix use something like
Code:
plot(matrix(1,:),matrix(2,:))

You should be able to find how to change line colors in the online MATLAB docs.
 
hold all;

will plot each successive dataset in a different colour.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K