MATLAB: Convert workspace of cells to double

cell arrayscell2matMATLAB

Hi I have a workspace which is full of cell arrays I want a way which can change the entire workspace to double array.
rite now my workspace is small so i am able to use cell2mat(variable name). But there is a good chance it will increase in the future. Can anyone help me with it.

Best Answer

We keep on saying that eval and co. are bad practice for good reasons. Yes, it may make it easy to create all these variables that you can easily see in your workspace with recognisable names but ultimately, it just make it harder to use these variables programmatically. As you've found out when you want to convert all of them. So really, don't do it! Ultimately, you'll find that the alternative are easier to use.
Changing your code to create a structure is easy. Replace the code in the (useless) ii loop by:
somestructname.(myheader{ii}) = mydata(:, 1);
However, assuming that you're using a fairly recent version of matlab all your problems (dynamic names, cell array, renaming) would mostly go away if you used readtable to read your excel files:
aliases = readtable('varnames.xlsx', 'Sheet', 'sheet1'); %import alias spreadsheet
aliases(ismissing(aliases.RealName), :) = []; %remove empty rows (if any)
aliases.importname = matlab.lang.makeValidName(aliases.AliasName); %actual variable name when imported
opts = detectImportOptions('dataset.xlsx');
[match, index] = ismember(aliases.importname, opts.VariableNames); %find real name of columns
opts.VariableNames(match) = aliases.RealName(index(match)); %replace column name
if ~all(match)
warning('Some columns do not have aliases: %s', strjoin(opts.VariableNames(~match), ', '));
end
opts.SelectedVariableNames = opts.VariableNames(match);
opts.VariableUnitsRange = 'A2'; %to import the unit row
dataset = readtable('dataset.xlsx', opts'); %automatically import with correct column name and type