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!