I'm working on a project and I need to work with certain variables from the workspace and I only have their name as a char array.
To make an example, I have array
var_names = {'var1', 'var2', ... }
and these variables are (among many others) in the workspace as structs with multiple attributes - value, class etc. (I believe these are Simulink generated but I am not absolutely certain).
To simplify, say I have the names {'var1', 'var2'} and I need to make a product of their values
prod = var1.Value * var2.Value
I tried things like
var_names(1).Value * var_names(2).Value
and similar more obvious attempts but none were successful. A note - the eval doesn't work because of the struct nature of the variables and I need something else.
masterStruct.(var_names{1}). This is much faster thaneval.