6

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.

1 Answer 1

1

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
3
  • It works! Thank you so much :). But i still have one more question. What if i want to display it as a line or use dash instead of asterisk (*) Dec 22, 2012 at 6:44
  • In that case, you may want to download and use cline from the Matlab File Exchange. Also, if you found my answer helpful, please consider upvoting and/or accepting it.
    – Jonas
    Dec 22, 2012 at 20:05
  • Oh i'm sorry, i accept your answer and upvoting it. Thank you so much. Oh that cline, I tried that too but the method that you gave me (scatter3) works better than the cline. I couldn't upload the result images in here, but i prefer your method. Thank you so much :) Dec 23, 2012 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.