How can I use a colormap to color each row in a matrix the same color?

15 views (last 30 days)
I have two matrices of lat and lon coordinates. Each one is size (25,300), where each column is a measurement and the rows correspond to separate pathways. For example, lat(1,300) is all the latitude measurements for the 1st pathway, and lon(1,300) is all the longitude measurements for the 1st pathway.
I want to plot all of the pathways lats and lons, but each separate pathway has its own color.
I currently have:
colororder(parula(300))
plot(lon,lat,'Marker','o','LineStyle','none')
Which plots all pathways, but the colormap is changing throughout all measurement (e.g. every measurement has its own color), instead of each row getting its own separate color.
If I run colororder(parula(25)) it also doesn't do what I want. Instead, it plots the first 25 points as one color, then 25 points as the next color, and it does this 25 times then resets to start at the first color.
Essentially, I want it to plot the first row of 300 points as 1 color, then the second row of 300 points as the next color, etc. etc. until the 25 rows are colored.

Accepted Answer

Stephen23
Stephen23 on 15 Jun 2022
Edited: Stephen23 on 15 Jun 2022
You need to transpose the input matrices, so that PLOT() gets 300*25 matrices:
colororder(parula(25))
plot(lon.',lat.','Marker','o','LineStyle','none')
% ^^ ^^ transpose
Although you write that you "want it to plot the first row of 300 points as 1 color..." the PLOT() function does not plot rows of a matrix and probably never will. For non-vector inputs, PLOT() plots the columns, just as the documentation explains. So the simple solution is to give it exactly the input data that its documentation required: if you want to plot 300 points as one color then those 300 points should be the first column, etc.
Ergo, transpose the input matrices.
  2 Comments
Jeremy Salerno
Jeremy Salerno on 15 Jun 2022
Thank you! I now see that in the plot documentation about columns. What is the meaning of the "." after lon and lat? I noticed the code runs without it, as well. New to Matlab still.
Stephen23
Stephen23 on 15 Jun 2022
"What is the meaning of the "." after lon and lat?"
  • .' transpose
  • ' complex conjugate transpose
If you don't want the complex conjugate then use transpose.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!