フィルターのクリア

How to plot values with different color with "if statement"

3 ビュー (過去 30 日間)
Ivan Mich
Ivan Mich 2020 年 6 月 7 日
コメント済み: J. Alex Lee 2020 年 6 月 8 日
Hello,
I have a question. I have an .xlsx file with 3 columns. After that, I am making calculation between two first values. I would like to plot values x,y, depending on the value of the 3rd column (for example I would like to plot blue circle if 3rd column has 0 value and if 3rd column has 1 value I would like to plot red cirlce).
Could anyone help me?

回答 (2 件)

J. Alex Lee
J. Alex Lee 2020 年 6 月 7 日
look at the documentation for the "scatter()" command. can you do what you want with that?
  2 件のコメント
Ivan Mich
Ivan Mich 2020 年 6 月 7 日
編集済み: Ivan Mich 2020 年 6 月 7 日
Excuse me , but I don;t understand you. Could you be more specific?
I want my x-y plot colors to depend on the value of the third column.
For example , for value 1 of the third column the color of the x y plot to be red.
for value 2 of the third column the color of the x y plot to be blue.
for value 0 of the third column the color of the x y plot to be green.
That's what I mean
J. Alex Lee
J. Alex Lee 2020 年 6 月 8 日
did you read the documentation for scatter()?
If you don't have stats toolbox for Ameer's answer, you can achieve the same thing with scatter()
x = [0.5 0.2 0;
0.2 0.3 1;
0.6 0.2 0;
0.9 0.6 0;
0.2 0.4 0;
0.4 0.8 1;
0.7 0.9 1;
0.1 0.2 0];
colors = [1 0 0; % red for 0s
0 0 1]; % blue for 1s
scatter(x(:,1), x(:,2),[],x(:,3))
colormap(colors)

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


Ameer Hamza
Ameer Hamza 2020 年 6 月 8 日
x = [0.5 0.2 0;
0.2 0.3 1;
0.6 0.2 0;
0.9 0.6 0;
0.2 0.4 0;
0.4 0.8 1;
0.7 0.9 1;
0.1 0.2 0];
colors = [1 0 0; % red for 0s
0 0 1]; % blue for 1s
gscatter(x(:,1), x(:,2), x(:,3), colors)

カテゴリ

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