From: tracy on
Hello,

I have a question that I am hoping someone here can help me with. I have a 82*100 matrix and for each row, I want to specify a certain range of values (3 different ranges) a specific color AND these ranges change for each row. For example, say anything in (1,:) is between -400: -100 I want it to be blue, and anything between -100: 500 to be black, and anything between 500: 800 I want to be red. Then for (2,:), I have a different group of rangers to be those three colors. Does anyone have any idea how to do this?


Thanks so much in advance,

Tracy
From: us on
"tracy " <tracyaromano(a)gmail.com> wrote in message <i2i9o7$qps$1(a)fred.mathworks.com>...
> Hello,
>
> I have a question that I am hoping someone here can help me with. I have a 82*100 matrix and for each row, I want to specify a certain range of values (3 different ranges) a specific color AND these ranges change for each row. For example, say anything in (1,:) is between -400: -100 I want it to be blue, and anything between -100: 500 to be black, and anything between 500: 800 I want to be red. Then for (2,:), I have a different group of rangers to be those three colors. Does anyone have any idea how to do this?
>
>
> Thanks so much in advance,
>
> Tracy

a hint:
- re-index -or- enumerate your matrix according to the unique colors you want...
- create a color map matching these indices/numbers...

us
From: Jan Simon on
Hi Tracy,

Range = [ ...
0.1, 0.3, 0.5; ...
0.2, 0.7, 0.6]; % Limits for the columns
Xseparated = repmat(2, size(X));
Xseparated(bsxfun(@lt, X, Range(1, :))) = 1; % Or "le" ?
Xseparated(bsxfun(@gt, X, Range(2, :))) = 3; % Or "ge" ?

Good luck, Jan
From: us on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i2id51$s14$1(a)fred.mathworks.com>...
> Hi Tracy,
>
> Range = [ ...
> 0.1, 0.3, 0.5; ...
> 0.2, 0.7, 0.6]; % Limits for the columns
> Xseparated = repmat(2, size(X));
> Xseparated(bsxfun(@lt, X, Range(1, :))) = 1; % Or "le" ?
> Xseparated(bsxfun(@gt, X, Range(2, :))) = 3; % Or "ge" ?
>
> Good luck, Jan

one of the other solutions

% the data
m=[
1 300 100
2 310 101
10 20 200
11 11 300
20 10 500
21 111 501
25 110 501
];
mr={ % <- ranges for each COL...
[0,10,50] % <- COL# 1
[0,50,200,400]
[0,150,400,600]
};
% the engine
clear ix;
nc=size(m,2);
% - enumerate M with unique indices...
[ix,ix]=arrayfun(@(x) histc(m(:,x),mr{x}),1:nc,'uni',false); %#ok
ix=cat(2,ix{:});
is=[0,cumsum(max(ix(:,1:nc-1)))];
mix=bsxfun(@plus,ix,is);
% - create colormap, eg, simply
cn=max(mix(:));
cmap=hsv(cn);
cmap(3,:)=[0,0,0]; % <- color for index #3...
cmap(7,:)=.5*[1,1,1]; % <- ... #7...
% the result
imagesc(mix);
colormap(cmap);
colorbar;
axis image;

us