How i plot vector in workspace but i have only name the vector i want plot
1 次查看(过去 30 天)
显示 更早的评论
HI
in my workspaceworkspace i have vectors, now i find the vector i want plot in this code:
namesWorkspace = who;
outStr = regexpi(namesWorkspace, 'nameOfVariable');
ind = ~cellfun('isempty',outStr);
vars = namesWorkspace(ind);
outStr = regexpi(namesWorkspace, 'BB');
ind = ~cellfun('isempty',outStr);
vars = namesWorkspace(ind)
result:
vars =
'BB1UN'
'BB1UR'
Now i want plot(BB1UN) and plot(BB1UR) How i do it?
i try this but its not work: plot(vars(1,1)) ; plot(vars(1,2))
BB1UN- Its vector in my workspace
BB1UR- Its vector in my workspace
0 个评论
回答(1 个)
A. Sawas
2019-4-13
编辑:A. Sawas
2019-4-13
plot(eval(vars{1})); % 'BB1UN'
plot(eval(vars{2})); % 'BB1UR'
3 个评论
A. Sawas
2019-4-13
What I really started to hate in this community? ... when "expert" people use the word "beginners" when they don't like the solutions.
I am sure there are cases when using eval is not a bad thing, otherwise it shall be removed from Matlab.
Stephen23
2019-4-13
编辑:Stephen23
2019-4-14
"... otherwise it shall be removed from Matlab."
eval is not the problem: the problem is how beginners use it when other ways of writing code are simpler, neater, more efficient, less buggy, and easier to debug.
This topic has been discussed many times before:
"What I really started to hate in this community? ... when "expert" people use the word "beginners" when they don't like the solutions."
Interestingly those slow, complex, obfuscated, buggy and hard-to-debug "solutions" are discussed in some detail in the MATLAB documentation:
and on the official TMW blogs:
and in many threads on this forum, where many explanations (based on experimental data and an understanding of how MATLAB actually works) have been provided on why this approach to code design forces users into writing slow, complex, obfuscated, and buggy code that is hard to debug. Based on many threads on this forum, the use of those slow, complex, buggy "solutions" does seem to be more correlated with beginners.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!