convert structure class to double class

1 回表示 (過去 30 日間)
ha ha
ha ha 2017 年 11 月 23 日
編集済み: Stephen23 2017 年 11 月 23 日
Let's say:
A : 4x1 structure class
A= Field1 :[1000x1 double],
Field2 : [2x1 double],
Field3 : [5x1 double],
Field4 : [1x1 double]
A= Field1 : [1;2;3...;1000],
Field2 : [99;11],
Field3 : [44;11;33;88;66],
Field4 : [77]
Question: How can i convert "structure A" to "double class B" for the last third double ?
_Result_: B=[99;11;44;11;33;88;66;77]
  3 件のコメント
ha ha
ha ha 2017 年 11 月 23 日
編集済み: ha ha 2017 年 11 月 23 日
A is "structure class"
A is NOT "cell class".
Sorry.Plz see my edit
Birdman
Birdman 2017 年 11 月 23 日
Check my answer.

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

採用された回答

Stephen23
Stephen23 2017 年 11 月 23 日
編集済み: Stephen23 2017 年 11 月 23 日
Fake data:
>> A.F1 = [1;2;3];
>> A.F2 = 4;
>> A.F3 = [5;6];
>> A.F4 = [7;8;9];
To concatenate all fields of a scalar structure you could convert to cell array using struct2cell as an intermediate step:
>> C = struct2cell(A);
>> cat(1,C{:})
ans =
1
2
3
4
5
6
7
8
9
But most likely you would be much better off using a non-scalar structure, because then you can simply do this:
cat(1,A.field)
and also use simple-and-efficient indexing to access parts of the structure.

その他の回答 (1 件)

Stephen23
Stephen23 2017 年 11 月 23 日
編集済み: Stephen23 2017 年 11 月 23 日
Using your example cell array:
>> A= {[99;11], [44;11;33;88;66], [77]};
>> cat(1,A{:})
ans =
99
11
44
11
33
88
66
77

カテゴリ

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