Is there any command to get the base workspace variable name ?

2 Kommentare

Guillaume
Guillaume am 4 Dez. 2015
In which contest? within a function? Which variable? All of them? An input to a function?
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan am 4 Dez. 2015
Bearbeitet: Gopalakrishnan venkatesan am 4 Dez. 2015
I have a function like below
function data()
run('D:\......\comp.m')
end
so now comp.m will run and store the repective variable in base workspace.
Problem is now i need to get the name of the base workspace variables

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Thorsten
Thorsten am 4 Dez. 2015
Bearbeitet: Thorsten am 4 Dez. 2015

0 Stimmen

S = whos;
varname = {S.name};

5 Kommentare

Gopalakrishnan venkatesan
Gopalakrishnan venkatesan am 4 Dez. 2015
When I use this command i am getting only the local workspace variable name
True. To access the base workspace, use evalin
vars = evalin('base','who');
or
S = evalin('base','whos');
varname = {S.name};
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan am 4 Dez. 2015
Great . Thanks a lot. Now works fine.
Guillaume
Guillaume am 4 Dez. 2015
"use evalin": Here be dragons. Do not go down that path unless you know what you're doing and know all the pitfalls of using eval and its friends.
For what reasons do you want to have the list of variables in the base workspace?
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan am 4 Dez. 2015
Bearbeitet: Gopalakrishnan venkatesan am 4 Dez. 2015
I have a function like below
function data()
run('D:\......\comp.m')
end
so now comp.m will run and store the repective variable in base workspace only right. I need the variable name so oly. Like wise this will run in loops

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by