MATLAB: How to generate variable names automatically based on the data

assignincreateMATLABnamevariable

I want to create multiple variables to the Workspace such as: 'x1', 'x2', 'x3', … and so on depending on how long my data is.
How can I do this in MATLAB?

Best Answer

You can use the "assignin" function in a for loop to do this:
>> for i = 1:5
>> assignin('base',strcat('x',num2str(i)),i);
>> end