How to use cat properly
2 views (last 30 days)
I'm confused about the properly way of using cat and the help isn't being so helpful. Let's say that I have a variable var1
I want to rearrange "passing down" the last dimension. I know that this words make no sense in a matrix context, but please bear with me.
So the new size would be (31x9=279)
I'm currently using
var2 = cat(XX,var1(:,:,:));
If I use XX as 1,2,3 or 4, I get the same result, this is, the size I want. But, what does it mean in this context if I use XX as 1, 2, 3 or 4?
Matt J on 29 Mar 2022
Edited: Matt J on 29 Mar 2022
The cat command is not causing the change that you are seeing in the array shape. What's causing it is the fact that you are indexing with 3 subscripts (:,:,:) instead of 4. Since the cat command only receives 2 arguments it simply returns the 2nd argument unchanged. You could have equivalently generated var2 without cat as follows:
whos var1 var2
To do something meaingful with cat(), you must give it 3 or more input arguments, e.g.,
cat(1, var1,var2) %cat along dimension 1
cat(2,var1,var2) %cat along dimension 2
cat(3,var1,var2) %cat along dimension 3