Peterstone
Peterstone

Reputation: 7459

Create a vector of the workspace variables name

Related with a question I asked before MATLAB: Automatic detection of relations between workspace variables through functions. Does any knows how can I get a vector with conteins the variable names of the workspace variables? Thank you.

Upvotes: 0

Views: 2324

Answers (1)

Adrien
Adrien

Reputation: 1475

You might try:

variables_list = who;

However be aware that this might create a new variable variables_list if it did not exist prior to this command and that in this case the string 'variables_list' will not be in the list. You should also be careful with the special ans variable which might or might not show up, depending on your coding style. For the kind of things you want to do, you might try to combine this with evalin to get the list of variables of another workspace.

NB: Technically variables_listis not a vector but a cell array.

Hope this helps.

A.

Upvotes: 2

Related Questions