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

1 回表示 (過去 30 日間)
Yossi Benyakar
Yossi Benyakar 2019 年 4 月 13 日
編集済み: Stephen23 2019 年 4 月 14 日
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

回答 (1 件)

A. Sawas
A. Sawas 2019 年 4 月 13 日
編集済み: A. Sawas 2019 年 4 月 13 日
plot(eval(vars{1})); % 'BB1UN'
plot(eval(vars{2})); % 'BB1UR'
  3 件のコメント
A. Sawas
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
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 ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by