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

1 次查看(过去 30 天)
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.

采纳的回答

the cyclist
the cyclist 2013-7-6
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}])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by