Multiple line plots of matrix with color depending on other vector
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am pretty inexperienced with matlab, so sorry if I cannot express myself clearly.
I have a matrix A = 78x31 and I want to make a line plot of the rows, so 78 lines in total.
Additionally I want the range of the line colors to be dependent on the values of a vector B = 78x1.
So for example:
for row 1: B(1) -> 3.3 -> medium color
for row 2: B(2) -> 5.5 -> dark color
for row 3: B(3) -> 2.5 -> bright color etc..
I used the plot(A) before, which works fine, but gives me very random colors. scatter(A,B) does not do the job either.
Thank you in advance!
0 件のコメント
回答 (1 件)
Ameer Hamza
2018 年 6 月 26 日
The order of plot colors is decided by the ColorOrder property of the axes object. You can access this property as
ax = gca;
ax.ColorOrder
for R2014a and older
ax = gca;
get(ax, 'ColorOrder')
So if you have a colorMatrix corresponding to B vales i.e. [78 x 3] matrix, each row is an RGB color. i.e. B(1) = 3.3 -> [r g b]??? is the first row. You need to have RGB values corresponding to each value in B. Then you can use the colorMatrix to change the value of ColorOrder property.
ax.ColorOrder = colorMatrix;
For older versions
set(ax, 'ColorOrder', colorMatrix);
So the main task here is to generate such a colorMatrix based on values in vector B. Although it is possible to get such a colorMatrix using colormap() function, it is difficult to suggest an exact solution unless you can provide with a sample dataset.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!