assignment of colormap to values in matrix
2 views (last 30 days)
Show older comments
Tatiana Diachenko
on 25 Dec 2021
Edited: Tatiana Diachenko
on 27 Dec 2021
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
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.
Accepted Answer
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();
More Answers (0)
See Also
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!