assignment of colormap to values in matrix

2 views (last 30 days)
Hi, I'm plotting a surface with the help of mesh function.
I want to assign 'jet' color map to matrix A, and use it's absolute values in mesh. I want the minimum (of A) to be blue and the maximun to be red.
A, n1, n2, n3 all matrixes of the same size
B=abs(A)
x=(B.*n1);
y=(B.*n2);
z=(B.*n3);
mesh(x,y,z)
Not sure how to do it, thank you.
  2 Comments
Cris LaPierre
Cris LaPierre on 25 Dec 2021
Edited: Cris LaPierre on 25 Dec 2021
Save your variables A,n1,n2,n3 to a mat file and attach to you post using the paperclip icon. At the least, tell us the dimensions of each of them.
Tatiana Diachenko
Tatiana Diachenko on 27 Dec 2021
Edited: Tatiana Diachenko on 27 Dec 2021
Hi, Thank you
They are matricess of 361*361.
n1 n2 n3 defines a sphere with the radius 1. and A is some function .
n1=sind(theta).*cosd(phi)'
n2=sind(theta).*sind(phi)'
n3= cosd(theta).*ones(1,361)'
theta=0:0.5:180
phi=0:360

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Dec 2021
Are you sure?
The fact that you take abs(A) implies that A is expected to have either negative or complex values. Maximum and minimum of complex values are not defined, so you must be expected A to have negative values.
If your n3 might have negative values, then your z will have negative values. But if n3 might be less than negative 1 then your z could have values more negative than the minimum of A; if your n3 might have values greater than 1 then your z values could have values more positive then the maximum of A. If your n3 is restricted to positive, then z would have to be strictly non-negative and you would be wasting a lot of the color space since you want the color mapping to start from the mininum of A, not from the minimum absolute value of A...
sz = [48, 64];
A = randn(sz);
n1 = rand(sz);
n2 = rand(sz);
n3 = rand(sz);
B = abs(A);
x = B .* n1;
y = B .* n2;
z = B .* n3;
mesh(x, y, z);
caxis([min(A(:)), max(A(:))]);
colormap(jet);
colorbar();
  1 Comment
Tatiana Diachenko
Tatiana Diachenko on 27 Dec 2021
Hi, Thank you,
n3 has negative values that are smaller than 1, and A is not complex.
n1,n2.n3 define a sphere of radius 1.
n1=sind(theta).*cosd(phi)'
n2=sind(theta).*sind(phi)'
n3= cosd(theta).*ones(1,361)'
theta=0:0.5:180
phi=0:360
if I don't use abs(A) I get only half of my surface, but when I plot the surface with abs(A), I want to distinguish what values were negative and what values were positive in A with the colormap.

Sign in to comment.

More Answers (0)

Categories

Find more on Color and Styling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!