Change table variable dimension

6 views (last 30 days)
Soo Mee Kim
Soo Mee Kim on 17 Feb 2019
Commented: Peter Perkins on 18 Feb 2019
I have two multi-diemnsional array to be merged into a Table.
A : K x M x N x L array
B : K x M x N array
If I do table(A,B), it resulted in two columns with K rows as follows
Var1 Var2
--------------------- -------------------------
[1xMxNxL single] [1xMxN categorical]
...
I want to reduce the first dimension of each table element like
Var1 Var2
--------------------- -------------------------
[MxNxL single] [MxN categorical]
...
How to get the table?

Answers (2)

Image Analyst
Image Analyst on 17 Feb 2019
Not sure - I'd have to try some things with either table(), permute, or squeeze(). Look up squeeze and permute() in the help and experiment with some things. You might have to permute the K dimension to the end (last dimension). How many rows are there in the table?
  1 Comment
Soo Mee Kim
Soo Mee Kim on 18 Feb 2019
Table has 25377 rows.
when I try to apply squeeze or permute,
X{1,1} = squeeze(X{1,1})
or
X{1,1} = permute(X{1,1}, [2 3 4 1])
I got an error message of 'height mismatch between new assignment and the table.
I don't know how to change the diemension of each variable in the table like 1xMxNxL to MxNxL.
Thanks.

Sign in to comment.


Peter Perkins
Peter Perkins on 17 Feb 2019
You have created an Kx2 table, one of whose variables is KxMxNxL, the other is KxMxN. I don't know if that's what you intended, or if it's useful, or if you are lokking for something else. When you see things like [1xMxNxL siingle] (which obviously is not the actual output, it would help to see what you really get), it's just a display artifact. Var1 is stored in the table as a KxMxNxL array.
If you literally want an MxNxL array and a MxN array in each row of the table, you will need to split those numeric arrays into two Kx1 cell arrays, the first of which has an MxNxL array in each cell, the other an MxN array.
But it's not clear what you actually want.
  2 Comments
Soo Mee Kim
Soo Mee Kim on 18 Feb 2019
Actucally, Var1 and Var2 are MxNxL and MxN images, respectively.
I want to feed the table (dataset) into trainNetwork function.
But when I input the table into the function, I gote an error of unexpected size of images. The trainNetwork function can treat 3D or 2D images, but the table has 4D and 3D dimensions. So to feed the table into the function, I need to squeeze the unnecessary first diemension of each element in the table. That's waht I want to do.
Thanks.
Peter Perkins
Peter Perkins on 18 Feb 2019
If this
"A : K x M x N x L array
B : K x M x N array
If I do table(A,B)"
is true, then no, they are not. They are KxMxNxL and KxMxN, even inside the table.

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!