Avoid creating dynamically named variables in MATLAB. This ispoor practice as has been explained many times on this forum, and is not recommended by TMW/MATLAB themselves:
When you are a beginner it seems like a cunning and fast way to store information, but actually it isreally bad practice to name your variables dynamically. MATLAB is also not intended for this kind of variable naming: if you continue to include data in the variable names then you will find yourself fighting many more of these battles against MATLAB.
However when you usemore appropriate storage for your data (and meta-data) then you will suddenly find lots of MATLAB functions that do many useful operations for you, quickly and easily.
In your case a much more robust solution would be to use:
structures, where you can include fields for each kind of data (e.g. Process type, Flow data, Temperature data, Notes, Units, etc). Structures can even benon-scalar, which is extremely useful! And yes, you can even define structurefieldnames dynamically.
There are many functions that support working on structures and cell arrays and can access their data easily, and many functions operate on complete numeric arrays all at once without any loops (i.e.vectorized code, which is something you need to learn about).
Placing your data in a structure or cell array also makes it much easier to pass to functions: can you imagine the fight you would have trying to pass hundreds of dynamically named variables to a function?
If you have a newer version of MATLAB you can also use atable , which stores the data together in one array but also allows key-name access to the columns. This might be a good alternative for your data.
Not only that but using the functioneval makes your code very slow, extremely difficult to debug, and it obscure the code's meaning. Beginners often useeval for everything, and then complain that they cannot debug it, or that their code is very slow:
And in case you thought this is a MATLAB restriction, here is the same discussion for some other languages, advising "DO NOT create dynamic variable names":
Best Answer