scatter Plot , conditional color variation based on a third value

I am having difficulty changing the colors in scatter plot if the condition is based on a 3rd value. For example;
f_tot = rand(3,20);
rows = 3;
x = rand(3,20);
y = rand(3,20);
hold on
box on
for p = 1: 1:rows
if f_tot >= 0.8
c = 'red';
else
c = 'blue';
end
scatter(x(:,p),y(:,p),2,c);
end
f_tot decision seems to be completely ignored when executing the condition

4 件のコメント

Duncan Po
Duncan Po 2017 年 11 月 22 日
Instead of checking f_tot >= 0.8, you probably want to check f_tot(p) >= 0.8? f_tot is a matrix, and having a matrix in an if statement will always just use the first element. Also you probably want to do "hold on" after scatter. Otherwise the scatter plot starts from scratch at each iteration of the loop.
Zaharaddeen Hussaini
Zaharaddeen Hussaini 2017 年 11 月 24 日
Thanks a lot!
The f_tot(p) bit did all the trick.
Nitika Kandhari
Nitika Kandhari 2018 年 6 月 26 日
Hi, If instead of just 2 colors- red and blue; I need a gradient between blue and red, how would I do that??
I am doing this:
t = 1:3580; %%Time length on the x-axis
for i = 1:1803
if z(i,t) > 0.25
scatter(t, inv(i,t), [], z(i,t), 'filled') %%Plot inverse velocity (inv- 1803*3580 matrix) against time for all data points and color them according to values in the z-matrix (1803*3580)
hold on
end
end
colormap(jet)
If I do no give the if command, my plot looks like the file attached. Essentially, I want to filter out the data points with lower values in z-matrix (blue points). Only the data points having values higher than 0.25 need to be there in the plot. Any ideas??
Nitika Kandhari
Nitika Kandhari 2018 年 6 月 27 日
I got the answer and I am writing it here in case anyone else needs to do the same.
z(z <= 0.25) = nan;
This replaces the values lower than 0.25 and takes out the noise (blue dots) and filters the data.

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

回答 (0 件)

カテゴリ

質問済み:

2017 年 11 月 22 日

コメント済み:

2018 年 6 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by