MATLAB: Horizontally concatinating the fields of a structure with different dimensions.

cellcell arrayconcatinatefieldhorzcatMATLABstructures

i have a [1*1] structure containing 30 fields,
variable00,,…… variable29 with size [8193*2, 8192*2….8189*2] (random size every time)
I want to concatinate all the data in one field 'allvariable' but with the dimension missmatch i am unable to do that.
Also is there a way to concatinate only the first rows?
One random data picture is attached.2019-01-14_11h15_31.png

Best Answer

The different number of rows does not prevent them from being concatenated vertically:
>> S.f1 = [0,1;2,3;4,5];
>> S.f2 = [6,7;8,9];
>> C = struct2cell(S);
>> vertcat(C{:})
ans =
0 1
2 3
4 5
6 7
8 9
If you want to concatenate horizontally either use indexing:
>> D = cellfun(@(m)m(1:2,:),C,'uni',0);
>> horzcat(D{:})
ans =
0 1 6 7
2 3 8 9
or download catpad. from FEX:
>> catpad(2,C{:})
ans =
0 1 6 7
2 3 8 9
4 5 NaN NaN