4

I want to plot discrete 2D images at 13 z locations at [4:4:52] using the following lines of code.

a=100;
[mesh.x,mesh.y,mesh.z] = meshgrid(1:1:100,1:1:100,4:4:52);
a_unifdist=0;
b_unifdist=10;
noise=a_unifdist+(b_unifdist-a_unifdist).*rand(100,100,13);
c = (a./mesh.x)+noise;
slice(c,1:100,1:100,4:4:52);

However, I get 13 continuous plots from 1 till 13 instead of 13 discrete locations as shown below:

enter image description here

Could somebody tell me what's my mistake? I want the images to stack at [4:4:52] locations on z-axis. Thanks.

Community
  • 1
  • 1
  • related question: [Plotting multiple images in 3D-space](http://stackoverflow.com/q/7689586/97160) – Amro Jul 03 '12 at 20:53
  • Amro: Thanks. Actually I came to know about the function `slice()` from that post itself. However, that question is with regards to actual images than matrices (which is my problem). –  Jul 03 '12 at 20:57
  • btw, you shouldn't use `mesh` as a variable name (its already the name of a MATLAB function) – Amro Jul 03 '12 at 21:33

1 Answers1

15

Perhaps you meant:

slice(mesh.x, mesh.y, mesh.z, c, [], [], 4:4:52)

Here is a more interesting example than random data:

load mri
D = double(squeeze(D));

h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.1)

screenshot

Amro
  • 123,847
  • 25
  • 243
  • 454
  • That's correct! Apparently, it's giving first three images from bottom as colored, but, the rest of the 10 images as black. How to correct that? –  Jul 03 '12 at 21:08
  • @S_H: sorry, fixed. If the data is too dense, you can subsample along the x/y directions: `c(1:4:end,1:4:end,:)` and so on for `mesh.x`, `mesh.y` and `mesh.z` – Amro Jul 03 '12 at 21:28
  • Amro: I am sorry but I did not understand your last comment. Can you explain what does that mean? I changed the variable name `mesh` to `Grid`. –  Jul 03 '12 at 21:54
  • @S_H: First of all, I fixed the first line, I hope you saw the edit. Now the slices should render correctly for your case. As to my comment, I simply meant that if you found the plot to be too crowded, try to reduce the resolution of the grid; Instead of generating x/y using `1:100` in the `meshgrid` call, reduce it to say `1:4:100` – Amro Jul 03 '12 at 21:58