How to change M*1*N matrix to M*N matrix

I have a signal M*K*N matrix , and I want to display an slice of signal in xz plane something like: imagesc(a( : , 1, : )) but a( : , 1, : ) is considered as 3 dimensional matrix and can not be shown and always this message appears :
imagesc(abs(a(:,1,:)))
??? Error using ==> image
Error using ==> image
Indexed CData must be size [MxN], TrueColor CData must be size [MxNx3]
Error in ==> imagesc at 19 hh = image(varargin{1},'CDataMapping','scaled');
how can change this 3d matrix to a 2d with M*N?

 Accepted Answer

permute(a,[1 3 2])

4 Comments

I have used
b=permute(a,[1 3 2])
imagesc(abs(b(:,:,1)))
It works fine
thank you very much!
PERMUTE is an overkill here, which uses the implictely vanishing last singleton dimensions. The direct approach is:
reshape(a(:, :), size(a, 1), size(a, 3);
This is done automatically inside SQUEEZE.
I too have used this...and it works fine.. thank u so much..
I appreaciate your answer Jan. I tworks perfect:)

Sign in to comment.

More Answers (1)

Hi, use squeeze()
X = randn(10,1,10);
Y = squeeze(X);

2 Comments

In my experience, permute() is a more robust option than squeeze(). In particular, if any other dimension of the input array also happens to be length one, you might unexpectedly squeeze it away.
Right. In cases I know the dimensions I prefer reshape: say a is of size Mx1xN, I use b = reshape(a, M, N);

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!