How can I pass variables to eval without error suppression ?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Patrick Bernier
il 17 Ott 2019
Commentato: Patrick Bernier
il 18 Ott 2019
I'm trying to not use the error suppression on a line and to eliminate the console output of a function using evalc.
a = 1; % Matlab tells me this value might be unused.
b = [1 1]; %ok<NASGU> <- I'm also trying to not use those where possible.
evalc('fun(length(b),b,a)');
Is there a way to acheive both of my goals ? I feel like I'm either stuck with the console output or the error suppression message.
Thanks for your help.
3 Commenti
Risposta accettata
Guillaume
il 18 Ott 2019
f = @() func(numel(b), a, b); %prepare function for call
evalc('f()'); %call function. () optional but make it clear we're calling a function
limits the content of eval to the struct minimum and avoids the mlint warning about unused variables (except maybe f)
0 Commenti
Più risposte (1)
Walter Roberson
il 17 Ott 2019
sprintf('%g', a, b);
This will not work for non-numeric variables.
4 Commenti
Walter Roberson
il 18 Ott 2019
This is a new additional call whose output is intended to be thrown away. The only reason to add it is to silence the analyzer warning.
a=whatever
b=whatever
sprintf('%g', a, b); %use a and b to silence analysis
evalc('whatever')
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!