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

조회 수: 2(최근 30일)
Jeremy Salerno 2022년 6월 15일
댓글: Stephen23 2022년 6월 15일
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 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표시숨기기 이전 댓글 수: 1
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.

댓글을 달려면 로그인하십시오.

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by