Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by