Extracting fieldnames and values from a struct and converting to strings
7 views (last 30 days)
Show older comments
Commented: Jason on 17 Dec 2020
I have a struct containing information from a camera configuration (using imaq)
struct with fields:
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:
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.
Walter Roberson on 17 Dec 2020
strjoin(cellfun(@(N,V) N+"="+V, fieldnames(currentConfiguration), struct2cell(currentConfiguration), 'uniform', 0), '\t')
More Answers (0)
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!