hi,I have a 5-dimensional matrix and I want to pull out 3 dimensions. How do I do that?

1 view (last 30 days)
I have a 5-dimensional matrix and I want to pull out 3 dimensions. How do I do that?

Answers (1)

Adam Danz
Adam Danz on 10 Sep 2018
help squeeze
Example:
d = rand(3,4,5,6,7);
s = squeeze(d(:,:,:,1,1));
>> ndims(s)
ans =
3
>> size(s)
ans =
3 4 5
  2 Comments
Stephen23
Stephen23 on 10 Sep 2018
For that example squeeze is not required:
>> d = rand(3,4,5,6,7);
>> s = d(:,:,:,1,1);
>> size(s)
ans =
3 4 5
Adam Danz
Adam Danz on 10 Sep 2018
Oh yeah... thanks, Stephen. So you might not need squeeze, Ron, depending on what you're doing.
Here's an example where squeeze is useful:
d = rand(3,1,1,6,7);
size(d)
ans =
3 1 1 6 7
s = squeeze(d);
size(s)
ans =
3 6 7

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!