Extracting fieldnames and values from a struct and converting to strings

2 ビュー (過去 30 日間)
Jason
Jason 2020 年 12 月 17 日
コメント済み: Jason 2020 年 12 月 17 日
Hello.
I have a struct containing information from a camera configuration (using imaq)
currentConfiguration =
struct with fields:
TriggerType: 'manual'
TriggerCondition: 'none'
TriggerSource: 'none'
I would like to append all the fields to a UITextArea hence need to extract all the fields as strings. I have tried the following:
str=sprintf('%s\t', currentConfiguration(1:end));
ReportMessage(app,str); %This is my function to append to a UITextArea
But I get the message
'Error using sprintf
Function is not defined for 'struct' inputs.
How do I get the field name and its value all as one string, and for all fields.
thanks
Jason

採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 17 日
strjoin(cellfun(@(N,V) N+"="+V, fieldnames(currentConfiguration), struct2cell(currentConfiguration), 'uniform', 0), '\t')
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 17 日
strjoin(cellfun(@(N,V) N+"="+V, fieldnames(currentConfiguration), struct2cell(currentConfiguration)), '\t')
Jason
Jason 2020 年 12 月 17 日
perfect, thankyou

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by