Dynamic Structure FieldNames in App Designer Properties

Hello,
I'm new to App Designer. Hoping this great community can help me :)
Aim:
  • I want to make a structure which uses dynamic field names available to all call back functions (make it a property) in App Designer
Background:
  • The dynamic field names are based on file names that user will import in - Field names could be any string (I do not know)
Supporting image:
Question: How do I make all structure with dynamic field names available as a property please?
Thanks,
Jack

댓글 수: 2

Stephen23
Stephen23 2023년 10월 31일
편집: Stephen23 2023년 10월 31일
"The dynamic field names are based on file names that user will import in - Field names could be any string"
Avoid doing this. It is very fragile/latent buggy code because not all valid filenames are valid fieldnames.
Consider for example these valid filenames:
'x-y'
'x.y.z'
'0'
So to make this work robustly you would need to mangle all filenames using e.g. matlab.lang.makevalidname but this still does not exclude the possibility of non-unique fieldnames, so your code could still overwrite data without any warning. You would need to add extra code to avoid overwriting data.
Basically the entire approach fragile and best avoided.
The cause is due to your forcing meta-data (e.g. filenames) into fieldnames. Meta-data is data. Data belongs in arrays, not in field or variable names. Once you store that data in an array (e.g. non-scalar structure, table, etc) then your code will be much more robust.
Thanks for the feedback
I understand your points - I will correct

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

 채택된 답변

Voss
Voss 2023년 10월 30일

0 개 추천

Make global_struct an app property, and refer to app.global_struct everywhere in your code where you refer to global_struct now.

댓글 수: 2

Thanks, this worked well! (just managed to trial it now)
Great! You're welcome!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2023년 10월 30일

댓글:

2023년 11월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by