I have some MATLAB image data with the following dimensions (output is from MATLAB):
>> size(im)
ans =
86 86 3 45
The data imports just fine in Mathematica, except the dimensions are reversed, and there's one extra dimension:
In[179]:= i = Import["Attractims.mat"];
Dimensions[i]
Out[180]= {1, 45, 3, 86, 86}
It's easy enough to throw out that first dimension. But how can I massage the list to produce one whose dimensions are in the same order as in MATLAB? In other words, I want to reverse the order of the dimensions in a multi-dimensional list. At first this seemed like a trivial problem, but when I sat down to do it I found that I couldn't. Help?
EDIT:
If you want to check out the MATLAB file yourself, you can get it (for the time being) at:
[ edit: resource no longer available. ]
As I mentioned below in comments, I was unable to get Leonid's approach to change the dimensions of the imported data. However, R.M.'s approach almost works: the dimensions of the array are changed appropriately, but the X and Y are reversed. To see what I mean, download and import the data above using something like:
In[340]:= mma = Import["/wherever/Attractims.mat"];
In[341]:= mma2mat = Flatten[mma, Table[{i}, {i, Depth[mma] - 1, 1, -1}]];
In[342]:= Dimensions[mma2mat]
Out[342]= {86, 86, 3, 45, 1}
So far so good. But if you do:
Image[mma2mat[[All, All, All, 45, 1]], "byte"]
you can see that rows and columns have been transposed. I'm having a hard time wrapping my head around this thing, but if this produces the 'correct' image in MATLAB:
image(im(:,:,:,45))
then shouldn't the converted version do the same? In any event, thanks to your collective help I'm able to do the work that needs doing, but it would be nice to understand if I could...
Transpose
. It can handle multi-dimensional arrays. $\endgroup$Reverse
if it is a single vector $\endgroup$Flatten
you can drop the first dimension and transpose at the same time. $\endgroup$-v7.3
switch (see my answer). If you do this, then it gives you an upright image. $\endgroup$