MATLAB: How to load variable listed in folder one at a time and run a script sequentially

load variable sequence multiple

Dear all,
I have different .mat expressions (values) of the same variable VAR in a list of numerical arrays named differently stored in a folder: 'path to folder'\'array name'.VAR I want to import each VAR expression ('array name'.VAR) one at a time, run a script on the VAR value, name the output based on the 'array name' (such as 'array name'.OUTVAR), clear workspace except OUTVAR, then import the next VAR value on the list, run the same script, and iterate down the list. Please advise, I mention that 'array name' is not, say, 'file1', 'file2', but 'mark', 'john'
Many thanks,
Octavian

Best Answer

I suggest that instead of trying to create individual variables in the workspace for each array, that instead you use fields of a structure. For example,
ArrayName = 'mark';
results.(ArrayName) = ....