How i plot vector in workspace but i have only name the vector i want plot

1 view (last 30 days)
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

Answers (1)

A. Sawas
A. Sawas on 13 Apr 2019
Edited: A. Sawas on 13 Apr 2019
plot(eval(vars{1})); % 'BB1UN'
plot(eval(vars{2})); % 'BB1UR'
  3 Comments
A. Sawas
A. Sawas on 13 Apr 2019
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
Stephen23 on 13 Apr 2019
Edited: Stephen23 on 14 Apr 2019
"... 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.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!