2D plot with 3rd variable

7 ビュー (過去 30 日間)
Michel tawil
Michel tawil 2019 年 7 月 12 日
コメント済み: Michel tawil 2019 年 9 月 14 日
hey, i have many lines in X and Y axes, need to color each line according to a variable Z, how to do that ?
x
y
already plotted all the lines needed but need to add the color for each line according to the value of Z. for example if Z= 0 the line will take a color and if it;s 0.8 it takes another color( i mean how to add a colorbar for this )
thanks
  4 件のコメント
John Doe
John Doe 2019 年 7 月 12 日
You can modify the following code for your purposes.
where n will = the size of averageV
y(1:241,1) = 1:241
n = size(y, 1);
colors = hsv(n);
h = line([0 10], [y(1:241,1) y(1:241,1)])
set(h, {'color'}, num2cell(colors, 2));
Michel tawil
Michel tawil 2019 年 7 月 13 日
Hey, if it's only taking the size, how will it plot according to the value of averageV,
i want the line color plotted in XY according to the value of averageV not according to the size of averageV.
sorry for bothering again

サインインしてコメントする。

採用された回答

Cristian Garcia Milan
Cristian Garcia Milan 2019 年 7 月 12 日
Hello Michel,
I think you can use RGB colors so if you have the data in rows in X and Y it would be somethink like:
figure hold on for i = 1:size(X,1) plot(X(i,:),Y(i,:),'color',[Z(i) 0 1]) % There is needed that Z has a value from 0 to 1 for each row end
Hope it helps!
  4 件のコメント
Michel tawil
Michel tawil 2019 年 7 月 17 日
thank you, i guess this is exactly what i want. i'll make sure of it
Michel tawil
Michel tawil 2019 年 9 月 14 日
hello again, the plot3 didn't work.
My point is that for each line i am plotting, i want it to be colored according to a third variable ( that is the velocity of that line), the index of the lines and variables is not a problem, i just need a function in matlab that takes the color from a matrix different than the one used to plot(3rd variable)
nothing worked till now. i have 235 lines and each one of them has a velocity

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by