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')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by