Horizontally concatinating the fields of a structure with different dimensions.

5 ビュー (過去 30 日間)
ARN
ARN 2019 年 1 月 14 日
コメント済み: Stephen23 2019 年 1 月 14 日
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

採用された回答

Stephen23
Stephen23 2019 年 1 月 14 日
編集済み: Stephen23 2019 年 1 月 14 日
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
  2 件のコメント
ARN
ARN 2019 年 1 月 14 日
Thanks! desired answer is what i get from catpad but with zeros instead of NaN in the answer which i got from following.
g(isnan(g))=0;
Isn't there any simple way to do that? Lets say i am not allowed to use catpad.
Stephen23
Stephen23 2019 年 1 月 14 日
"Isn't there any simple way to do that? Lets say i am not allowed to use catpad."
The simple solution is to use catpad (it already exists, it works, it only requires one/two lines for you to get what you need). If you really do not want to use catpad then you could certainly use a few loops (or a few cellfun calls) to get the size of each matrix, then pad them as required, and then afterwards concatenate together. You would have to decide if that is "simple" or not.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by