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 comentarios

Stephen23
Stephen23 el 31 de Oct. de 2023
Editada: Stephen23 el 31 de Oct. de 2023
"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

Iniciar sesión para comentar.

 Respuesta aceptada

Voss
Voss el 30 de Oct. de 2023
Make global_struct an app property, and refer to app.global_struct everywhere in your code where you refer to global_struct now.

2 comentarios

Thanks, this worked well! (just managed to trial it now)
Voss
Voss el 1 de Nov. de 2023
Great! You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.

Productos

Versión

R2023b

Preguntada:

el 30 de Oct. de 2023

Comentada:

el 1 de Nov. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by