I have a process which is repeated on a set of data stored in separate folders. Each time a certain folders data is processed I need new variable names as I need to results
The MATLAB function genvarname does what you want. In your case it would look something like:
eval(genvarname('Set_', who)) = zeros(dim, number);
However, I would follow the recommendations of previous answers and use a cell or struct to store the results.
I'd not do it like this. It's a bad habit, it's better to use a cell array or a struct to keep multiple sets. There is a small overhead (size-wise) per field, but it'll be a lot easier to maintain later on.
If you really, really want to do that use eval
on the string you composed.
This sort of pattern is considered harmful since it requires the eval
function. See one of the following for techniques for avoiding it:
If you insist on using eval
, then use something like:
eval(sprintf('Set_1%d = zeros(dim, number);', number))