What is wrong with the code?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have this small code:
function test
L = 10;
t = existing_chk('L',uigetdir)
function x = existing_chk(name_x,a)
chk = exist(name_x,'var')
if chk == 0;
x = a;
else
x = eval(name_x);
end
end
end
The problem is that uigetdir is executed even though 'L' exists. I cannot figure out the problem
0 Commenti
Risposta accettata
Kelly Kearney
il 4 Mag 2011
The uigetdir function is being called on line 2 of your function, prior to existing_chk ever being called, since you have not enclosed the function name in quotes. The second argument of existing_chk should be a string. Replace that line with
t = existing_chk('L','uigetdir')
You should probably avoid using eval too, but that's just general programming advice; the function should work as written.
Più risposte (1)
Daniel Shub
il 4 Mag 2011
MATLAB evaluates uigetdir before existing_chk, so that it can pass whatever uigetdir returns to existing_chk. Either turn the second argument into a function handle @()uigetdir and call a() or turn it into a string 'uigetdir' and call eval(a).
0 Commenti
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!