how do I call an array by having a matrix which juxtaposes a standard name with a tag?

3 views (last 30 days)
I have many tables like so : TABLE_DD
TABLE_NN
TABLE_PP
...
and so on with various tags.
Is there any way to refer to the table by doing this :
>>A = ['TABLE_' Tags{1}];
where Tags = {'DD','NN','PP' ...};?
It would make life so much easier.

Accepted Answer

the cyclist
the cyclist on 6 Jul 2013
First, I would say you might want to take a look at this thread, which talks about using numbered cell arrays instead of sequences of variable names. It might point you to a better solution.
That being said, it is possible to do what you want:
TABLE_NN = rand(3);
TABLE_PP = rand(3);
tags = {'NN','PP'};
eval(['A = TABLE_',tags{1}])

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!