Imagesc defining only 3 colours for my entire data

5 vues (au cours des 30 derniers jours)
kyle lyth
kyle lyth le 18 Août 2013
hi i have a matrix that is 500x600 within this i have data values ranging from 0.2 to -0.2
i have looked at user the figure colour map editor but i cannot get my desired results.
i am hoping to set out a plot with these distinctive properties for the values:
0.2>x> 0.07 - Red
0.07>x>0 - green
x = 0 - Blue
0>x>-0.07 - Green
-0.07>x>0.2 - Red
is there anyway to alter the plot to show the results in this manner?
thanks for any help Kyle
figure(i)
subplot(3,1,1);
imagesc(ux);
axis equal off
colorbar

Réponses (1)

Image Analyst
Image Analyst le 18 Août 2013
Make a 256 row colormap. Then determine the index where the changes happen. For example 0 is at row 128, and 0.07 is at row 129 or whatever. Then make up the colormap and apply it
myColorMap(0:row1, :) = [1,0,0]; % Red
myColorMap(row1+1:127, :) = [0,1,0]; % Green
myColorMap(128,:) = [0, 0, 1]; % Blue
and so on.
  2 commentaires
kyle lyth
kyle lyth le 19 Août 2013
Modifié(e) : Image Analyst le 19 Août 2013
im not the best withmatlab so will need to spend some time having a look at this but thanks for your reply
i did however come up with a trivial solution where i searched the matrix 1 element at a time and replaced it with a new value for each of my colour options:
lx=0;
for x=1:LX-1
lx=lx+1;
ly=0;
for y = 1:LY-1
ly = ly+1;
if ux(ly,lx)<0.3 && ux(ly,lx)>=0.07
ux(ly,lx)=0.2;
elseif ux(ly,lx)<0.07 && ux(ly,lx)>0
ux(ly,lx)=.1;
elseif ux(ly,lx)<0.0 && ux(ly,lx)>-0.07
ux(ly,lx)=.1;
elseif ux(ly,lx)<=-0.07 && ux(ly,lx)>-0.3
ux(ly,lx)=.2;
% 0.2>x> 0.07 Red
% 0.07>x>0 - green
%x = 0 - Blue
%0>x>-0.07 - Green
%-0.07>x>0.2 - Red
end
end
end
Image Analyst
Image Analyst le 19 Août 2013
That can be vectorized into 3 faster lines. But anyway, I don't see how that applies colors.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Red 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!

Translated by