Extracting fieldnames and values from a struct and converting to strings

4 次查看(过去 30 天)
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')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by