MATLAB Answers


This question is closed. Reopen it to edit or answer.

Plotting a data from a matrix

1 view (last 30 days)
Suchetana Gupta
Suchetana Gupta on 2 Jun 2015
Closed: MATLAB Answer Bot on 20 Aug 2021 at 17:08
Hi I have a matrix where there are 11 rows and 198 columns. The values range between -1 to +1. I would like to plot the values (1 to 198 on x axis and 11 (random 11 sets)) in such a way that the positive values get red colour and the negative values get blue colour. How do I go about it? Thanks

Answers (1)

Walter Roberson
Walter Roberson on 2 Jun 2015
colidx = 1 + (YourMatrix >= 0);
surf(YourMatrix, colidx);
colormap([0 0 1; 1 0 0]); %blue; red
If you are thinking of a line plot then you need to define what should happen for lines that go between positive and negative points. You might want
mesh(YourMatrix, colidx);
  1 Comment
Suchetana Gupta
Suchetana Gupta on 2 Jun 2015
@Walter I am not looking for this. What I am looking for is something like what I have attached in the image.


Community Treasure Hunt

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

Start Hunting!

Translated by