Matrix indexing and plotting related doubt.

I am having a 3D matrix with 20 rows (x direction) , 50 cols (y direction) and 187 points ( z direction ,3rd dimension ). I want to view the plane described by x = 3 . i.e the the z-y plane at x= 3.
I have used the syntax
disp(A(3,:,:)) ;
but it's showing the result as (:,:,35115) cols 1 through 50 etc. what I want is the 50 cols with 187 points each .
Also I want to ask that, how can I plot a single column of a 3D matrix. example A(5,4,:) this will be a set of points ( 187 points ) in the z-direction. I want to plot these points only .

Answers (1)

It seems as if you need to use squeeze to get a 2D matrix
mat = zeros( 20, 50, 187 );
len = numel( mat );
mat = reshape( (1:len), size(mat) );
imagesc( squeeze( mat(3,:,:) ) )
disp( squeeze( mat(3,:,:) ) )
See also: Exploring Volumes with Slice Planes in the documentation

9 Comments

May you tell me what's there in the y and the x axes respectively in this plot? ( I see a color plot on my matlab )
imagesc(C) displays the data in array C as an image that uses the full
range of colors in the colormap. Each element of C specifies the color
for 1 pixel of the image. The resulting image is an m-by-n grid of pixels
where m is the number of columns and n is the number of rows in C. The row
and column indices of the elements determine the centers of the
corresponding pixels.
I have written this code, The values in the plane (15, : , :) (y-z plane ) of this matrix is between 400.0 to 800.0 . The resulting image which I am getting is attached below.
The code which I have used is :
disp(C(15,:,:))
mat = C;
len = numel( mat );
mat = reshape( (1:len), size(mat) );
imagesc( squeeze( mat(15,:,:) ) )
disp( squeeze( mat(15,:,:) ) )
C is a 20 X 23 X 174 matrix. I want to display C(15, : , : ) a 23 X 174 matrix at x = 15.
Anything wrong with that picture?
What does
whos C
return?
And try
imagesc( squeeze( C(15,:,:) ) )
whos C returns :
endName Size Bytes Class Attributes
C 22x24x181 764544 double
Yes , the color contrast is not correct. I guess, The intensity of the color depicts the magnitude of the value inside the cell of the matrix. But it''s not according to the magnitude there.
per isakson
per isakson on 16 Jun 2018
Edited: per isakson on 16 Jun 2018
Regarding the picture
  • The x-axis is too long; the length is 187 rather than 181. Thus, I suspect the size of C used to produce the picture is not the size that you report, 22x24x181
  • You should take a second look at the code that you used. The values of the plotted variable, mat, are not those of your C. The values are created according to my original example, i.e. (1:len). The picture of my answer didn't show zeros( 20, 50, 187 ). You need to understand the code you use!
  • You didn't try imagesc( squeeze( C(15,:,:) ) ) as I proposed. Thus, I propose you do it now.
Thank you very much !

Sign in to comment.

Asked:

on 13 Jun 2018

Commented:

on 18 Jun 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!