Suppression failure on evalin command

3 Ansichten (letzte 30 Tage)
Ian
Ian am 28 Nov. 2014
Bearbeitet: Jan am 12 Aug. 2017
I'm having a problem suppressing the evalin function when using it to change elements in a vector. The semi-colon isn't working. Is there a fix for this? Here's an example:
>> i=zeros(1,4);
>> evalin('base','i(1)=1');
i =
1 0 0 0
The semicolon doesn't suppress the output for some reason.

Akzeptierte Antwort

Mischa Kim
Mischa Kim am 28 Nov. 2014
Bearbeitet: Mischa Kim am 28 Nov. 2014
Ian, put the semi-colon right after the i(1)=1 statement
evalin('base','i(1)=1;')

Weitere Antworten (2)

Jan
Jan am 11 Aug. 2017
Bearbeitet: Jan am 12 Aug. 2017
It would be much more simple and efficient to omit the indirection over evalin:
i(1) = 1;
See the excellent explanations at tutorial:why-variables-should-not-be-named-dynamically-eval . You find a detailed analysis of the problems evalin causes here at: Answers: is-there-the-more-elegant-way-to-do-this#comment_476583

Ian
Ian am 28 Nov. 2014
So simple, yet so effective. Thanks!

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by