Convert Cell to Struct

5 ビュー (過去 30 日間)
Anand CU
Anand CU 2017 年 7 月 20 日
コメント済み: Anand CU 2017 年 7 月 20 日
I'm trying to access contents of a cell array which has 4 structures.
celldisp(tracks_array);
gives output:
tracks_array{1} =
kalmanFilter: [1×1 vision.KalmanFilter]
id: 0
totalVisibleCount: 1
bbox: [390 171 70 39]
consecutiveInvisibleCount: 0
age: 1
tracks_array{2} =
kalmanFilter: [1×1 vision.KalmanFilter]
id: 1
totalVisibleCount: 1
bbox: [459 175 40 24]
consecutiveInvisibleCount: 0
age: 1
tracks_array{3} =
kalmanFilter: [1×1 vision.KalmanFilter]
id: 2
totalVisibleCount: 1
bbox: [220 156 159 91]
consecutiveInvisibleCount: 0
age: 1
tracks_array{4} =
kalmanFilter: [1×1 vision.KalmanFilter]
id: 3
totalVisibleCount: 1
bbox: [510 159 68 49]
consecutiveInvisibleCount: 0
age: 1
Then I Use a for loop to iterate through the elements..
for elmen = tracks_array
structtt=cell2struct(elmen(1),{'id','bbox','kalmanFilter','age','totalVisibleCount','consecutiveInvisibleCount'},2);
This gives error of
Error using cell2struct
Number of field names must match number of fields in new structure.
Then I used this inside the for loop
disp(elmen)
celldisp(elmen)
gives,
[1×1 struct]
elmen{1} =
kalmanFilter: [1×1 vision.KalmanFilter]
totalVisibleCount: 1
bbox: [390 171 70 39]
consecutiveInvisibleCount: 0
id: 0
age: 1
I want to access the elements by their field names. How do I do this?
Right now if I try:
elmen.id
or
getfield(elmen,'id')
gives error
Struct contents reference from a non-struct array object.

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 7 月 20 日
structtt = cat(1,tracks_array{:});
  3 件のコメント
Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日
Anand CU
Anand CU 2017 年 7 月 20 日
Thank You..

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

その他の回答 (1 件)

Massimo Zanetti
Massimo Zanetti 2017 年 7 月 20 日
  1 件のコメント
Anand CU
Anand CU 2017 年 7 月 20 日
i get Struct contents reference from a non-struct array object. error

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

カテゴリ

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