Multiple line plots of matrix with color depending on other vector
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Ameer Hamza
le 26 Juin 2018
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 commentaires
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!