MATLAB: How to add variables in workspace with names derived from a char array and corresponding values stored in a double array

bad ideabuggycomplexdynamically named variablesMATLABslow

char array col_names = [time; speed; distance…] and double array data = [0;1;2;3… ,10;20;30;40.. ,5;6;7;8…]. col_names is a mXn matrix and data is a kXm matrix. I need to generate workspace variables time, speed, distance.. with their value content coming from data matrix

Best Answer

Here is an example
col_names = ['time ';'speed'];
data = [0 1;2 3;4 5];
for m = 1:2
eval(sprintf('%s = data(:,m)',col_names(m,:)));
end
HTH
Related Question