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 Comments

"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

Sign in to comment.

 Accepted Answer

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

2 Comments

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

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 30 Oct 2023

Commented:

on 1 Nov 2023

Community Treasure Hunt

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

Start Hunting!