How to Plot Multiple Matrices with Different Colors in Matlab?

In summary, the conversation discusses the difficulty in plotting a matrix with variable lengths and the desired outcome of plotting four matrices pointwise with different colored lines. The solution suggested is to use the "hold on" and "hold all" commands in MATLAB and to plot each matrix using the "plot" command. The color of the lines can be changed using the online MATLAB documentation.
  • #1
Funzies
20
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
  • #2
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.
 
  • #3
hold all;

will plot each successive dataset in a different colour.
 

1. How do I plot a matrix in Matlab?

To plot a matrix in Matlab, you can use the plot function. This function takes in the matrix as an input and plots the values on a graph. You can also customize the appearance of the plot by specifying parameters such as color, line style, and markers.

2. Can I plot multiple matrices on the same graph in Matlab?

Yes, you can plot multiple matrices on the same graph in Matlab. You can use the hold on command to plot multiple matrices on the same figure. This command ensures that the previous plot is not cleared before plotting the new one.

3. How do I label the axes of a matrix plot in Matlab?

To label the axes of a matrix plot in Matlab, you can use the xlabel and ylabel functions. These functions take in a string as an input and label the x-axis and y-axis, respectively. You can also use the title function to add a title to your plot.

4. Can I change the size and resolution of a matrix plot in Matlab?

Yes, you can change the size and resolution of a matrix plot in Matlab. You can use the figure function to specify the size of the figure and the saveas function to save the plot as an image with a specific resolution.

5. How do I plot a specific column or row of a matrix in Matlab?

To plot a specific column or row of a matrix in Matlab, you can use the indexing notation. For example, to plot the first column of a matrix A, you can use the command plot(A(:,1)). Similarly, to plot the second row, you can use plot(A(2,:)).

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
Back
Top