MATLAB Answers

How can I plot a 3-D mesh using the colorbar as the 4th dimension?

11 views (last 30 days)
Sarah Farthing
Sarah Farthing on 27 Jul 2018
Commented: KSSV on 28 Jul 2018
I am trying to plot the results of a function with 3 input variables.
I have used meshgrid to form 3, 3-D 10x10x10 matrices.
x = linspace(190,245,10);
y = linspace(140,560,10);
z = linspace(0.5,2,10);
[X, Y, Z] = meshgrid(x,y,z)
I then have a number of functions which generate the result I want to plot, let's call it "K", also a 3-D 10x10x10 matrix.
In my mind, I have the idea of a 3-D area with X, Y and Z as the axes and the result K is represented by the colour bar. I could then slice through this surface at various points of the axis to investigate the results there. I've tried using sliceomatic, https://uk.mathworks.com/matlabcentral/fileexchange/764-sliceomatic, but am receiving the following error:
Error using axes
Value must be a 1x2 vector of numeric type in which the second element is
larger than the first and may be Inf
Error in sliceomaticfigure (line 45)
d.axmain = axes('units','normal','pos',[.2 .2 .6 .6],'box','on',...
Error in sliceomatic (line 200)
d = sliceomaticfigure(d,xmesh,ymesh,zmesh);
Does anyone know how to correct this error or have another suggestion for how I could plot my data? I've already amended the sliceomatic script as detailed in the comments on the file exchange.
Thank you!

  0 Comments

Sign in to comment.

Answers (1)

KSSV
KSSV on 27 Jul 2018
x = linspace(190,245,10);
y = linspace(140,560,10);
z = linspace(0.5,2,10);
[X, Y, Z] = meshgrid(x,y,z) ;
figure
hold on
for i = 1:10
surf(X(:,:,i),Y(:,:,i),Z(:,:,i),Z(:,:,i))
end
colorbar

  2 Comments

Sarah Farthing
Sarah Farthing on 27 Jul 2018
Thanks for the suggestion, it doesn't give the flexibility I'm going for and I don't think I can define these "slices" as easily.

Sign in to comment.

Sign in to answer this question.


Translated by