How to cut a 3D matrix in Matlab, getting an array

Consider the presence of a three-dimensional matrix in the matrix, where

A(:,:,1) = [1 2 3;4 5 6;7 8 9]; A(:,:,2) = [11 22 33;44 55 66;77 88 99]; A(:,:,3) = [111 222 333;444 555 666;777 888 999]; 

Ok when i ask

 A(1:end,1,:) 

I get three different answers:

 A(1:end,1,1) = [1 2 3]; A(1:end,1,2) = [11 22 33]; A(1:end,1,3) = [111 222 333]; 

I want to get this in one instruction, possibly without loops, etc .:

 [1 2 3;11 22 33;111 222 333] 

How to get it?

I want the new matrix not to be a series of vectors.

Thankyou.

+4
source share
1 answer
 squeeze(A(1,:,:))' 

works. I think that if I were smarter or wanted to spend more time on it, I could do it without transposition, but this should point you in the right direction.

+7
source

Source: https://habr.com/ru/post/1411253/


All Articles