Try to access variable names dynamically will be buggy any slow, and is not recommended. No matter how much beginners love inventing the idea, trying to access variables names like this will always make code be slow and impossible to debug:
A much simpler, faster, and easier way to code this would be to put all of the data into one structure. Then the task is trivial:
S.X = 'anna';
S.Y = 'bob';
S.Z = 'cath';
C = fieldnames(S);
idx = listdlg('PromptString','Select variables',...
'SelectionMode','multiple',...
'ListString',C);
for k = 1:numel(idx)
S.(C{idx(k)})
end
Best Answer