scatter Plot , conditional color variation based on a third value

14 Ansichten (letzte 30 Tage)
Zaharaddeen Hussaini
Zaharaddeen Hussaini am 22 Nov. 2017
Kommentiert: Nitika Kandhari am 27 Jun. 2018
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 Kommentare
Nitika Kandhari
Nitika Kandhari am 26 Jun. 2018
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 am 27 Jun. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by