How i plot vector in workspace but i have only name the vector i want plot
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
A. Sawas
le 13 Avr 2019
Modifié(e) : A. Sawas
le 13 Avr 2019
plot(eval(vars{1})); % 'BB1UN'
plot(eval(vars{2})); % 'BB1UR'
3 commentaires
A. Sawas
le 13 Avr 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
le 13 Avr 2019
Modifié(e) : Stephen23
le 14 Avr 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.
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!