Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display values from a matrix in a custom colormap (Matlab)

I want to visualize a matrix based on the values its contain. I have one cell, which contains 11 matrices, each matrix has 4 columns which are x,y,z (the coordinate) and its values. I want to visualize this value, with location x, y, z and define my own colormap based on those values then display the colorbar. I want to use jet as the colormap. I want to use Blue to describe the maximal value and Red as the minimal value on the colormap. The values between maximal and minimal values have a color between red to blue.

This is the code that I already tried:

figure;
hold on
for i=1:length(diameter_lca)
    L2 = diameter_lca{i};
    dl1 = find(L2(:,4) > minimal_lca & L2(:,4)<2);%diameter 0-2
    dl2 = find(L2(:,4) >= 2 & L2(:,4) <= maksimal_lca);%diameter>2-maksimal
    x=L2(:,1);
    y=L2(:,2);
    z=L2(:,3);
    plot3(y(dl1),x(dl1),z(dl1),'*','Color','r');
    plot3(y(dl2),x(dl2),z(dl2),'*','Color','b');
end
daspect([0.488281 0.488281 0.625000]);
view(3); axis tight
camlight

In those code above, what I do is visualize the values on the 4th column from each matrix then I made a condition which is if the value is between 0-2, I gave red, and when it is between 2-maximal value of the 4th column, I gave blue.

Now, I need to display each value from the 4th column from each matrix in colormap jet without any condition like that.

like image 875
Nedya Utami Avatar asked Dec 21 '12 07:12

Nedya Utami


People also ask

How do you display Colormap in Matlab?

cmap = colormap returns the colormap for the current figure as a three-column matrix of RGB triplets. cmap = colormap( target ) returns the colormap for the figure, axes, or chart specified by target .

How do you use colormap jet in Matlab?

Description. c = jet returns the jet colormap as a three-column array with the same number of rows as the colormap for the current figure. If no figure exists, then the number of rows is equal to the default length of 256. Each row in the array contains the red, green, and blue intensities for a specific color.

What is colormap gray in Matlab?

newmap — Grayscale colormap Grayscale colormap, returned as an c-by-3 numeric matrix with values in the range [0, 1]. The three columns of newmap are identical, so that each row of map specifies a single intensity value. If you have Parallel Computing Toolbox installed, then newmap can also be a gpuArray.

How do I save a custom colormap in Matlab?

After you applied it, use the following code to get the required matrix for further reference: myCustomColormap = colormap(gca) save('myCustomColormap','myCustomColormap'); If you want to make the colormap generally available to all your functions, no matter where, add it to your Matlab search path.


1 Answers

The easiest would be to use scatter3:

%# make jet colormap from red to blue
cmap = flipud(jet(128));

%# plot values
figure,
scatter3(L(:,1),L(:,2),L(:,3),[],L(:,4),'marker','*')

colormap(cmap)
colorbar
like image 126
Jonas Avatar answered Sep 27 '22 22:09

Jonas