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

3 次查看(过去 30 天)
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.

采纳的回答

Stephen23
Stephen23 2022-6-15
编辑:Stephen23 2022-6-15
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 个评论
Jeremy Salerno
Jeremy Salerno 2022-6-15
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 2022-6-15
"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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by