Hot to concatenate two structs?

2 ビュー (過去 30 日間)
Umit
Umit 2012 年 8 月 6 日
I have following structs;
A.State = [12 10 5 5 5 5]
B.State = [11 11 1 1 1 1]
B.Detections = <1x1 struct>
B.Tracks = <1x1 struct>
I only need to concatenate A(:).State & B(:).State and create a new variable C(:).State. A & B may have more that 1 or more elements or 0 elements
C(:).State = [A(:).State B(:).State]
Is not working. I just need State part. Can you help me with that?
P.S: C is not created, A & B may have more than 1 element.

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 6 日
編集済み: Azzi Abdelmalek 2012 年 8 月 6 日
% copy and run this code, it works
A.State = [12 10 5 5 5 5]
B.State = [11 11 1 1 1 1]
C.State=[A.State B.State]
% the result
C =
State: [12 10 5 5 5 5 11 11 1 1 1 1]
  3 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 8 月 6 日
@Umit: "not even close" is your description of the problem, because with the info you supplied, Azzi's solution is more than valid.
So, I ask to be considerate and do not throw "not even close" at people who use their own time helping you. Put more effort at describing your problem and test the example you provide with the proposed soltuion BEFORE commenting.
Walter Roberson
Walter Roberson 2012 年 8 月 6 日
Azzi's solution does not meet the criteria of allowing for A and B with more than one elements (that is, that A and B might be structure arrays with length() > 1 for the structures.)

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by