How to access workspace variables one by one using m-script
17 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to read all workspace variables into array and check whether the name of variable is Matlab keyword or not. For example, I have four variables in workspace(a = 1;b=2;c=3;d=4;). I want to check if the varaible is keyword or not using matlab inbuilt function(iskeyword()) like below.
iskeyword('a')
ans =
0
>> iskeyword('if')
ans =
1
Is it possible check all base work space variables like this?
0 个评论
采纳的回答
Nobel Mondal
2015-6-1
You can get all the workspace variables like this:
>> varList = evalin('base', 'who');
Then check individual parameters:
>> iskeyword(varList{k}) % for k-th parameter
3 个评论
Nobel Mondal
2015-6-1
编辑:Nobel Mondal
2015-6-1
Ah, you're probably calling this from inside a function. You need to define the WorkSpace context: 'base' or 'caller'
Or else, you simply can try
>> varList = who;
If the scope isn't changing.
更多回答(1 个)
Azzi Abdelmalek
2015-6-1
a = 1;
b=2;
c=3;
d=4;
s1=whos
out=cellfun(@iskeyword,{s1.name})
4 个评论
Azzi Abdelmalek
2015-6-1
Maybe you need this
s1=whos
s2={s1.name}
for k=1:numel(s1)
out(k)=iskeyword(eval(s2{k}))
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!