How to extract a specific field value from struct

2 ビュー (過去 30 日間)
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 7 月 14 日
I am working in some data, and I have attained a struct (struct.mat) is enclosed.
struct with fields:
Connectivity: 8
ImageSize: [577 601]
NumObjects: 6
PixelIdxList: {[2695×1 double] [2934×1 double] [2877×1 double] [3002×1 double] [2733×1 double] [3078×1 double]}
I am intrested in extracting NumObjects data from this struct, so that I can use this as an input to some place. Kindly advise, how I can specifically extract this info (NumObjects: 6) as an output file, so I can use it as input some other place.
thank you

採用された回答

Stephen23
Stephen23 2022 年 7 月 14 日
編集済み: Stephen23 2022 年 7 月 14 日
load('struct.mat')
cc
cc = struct with fields:
Connectivity: 8 ImageSize: [577 601] NumObjects: 6 PixelIdxList: {[2695×1 double] [2934×1 double] [2877×1 double] [3002×1 double] [2733×1 double] [3078×1 double]}
val = cc.NumObjects
val = 6
  1 件のコメント
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 7 月 14 日
Issue resolved, exactly what I was looking for. Thanks alot for quick response.

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

その他の回答 (1 件)

Amritesh
Amritesh 2022 年 7 月 14 日
編集済み: Amritesh 2022 年 7 月 14 日
You can extract the NumObjects field using the name of struct/ after loading structName.mat file
NumObjects = structName.NumObjects;
Then, save NumObjects in NumObjects.mat file
save('NumObjects.mat','NumObjects');
You can also save all fields of struct as different variables in a file
save('newstruct.mat','-struct','structName');
Hope this resolves your problem.
  1 件のコメント
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 7 月 14 日
Thank you for assistance.

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

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by