Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
A problem about eval result in command window

Subject: A problem about eval result in command window

From: Galam Lee

Date: 30 May, 2012 06:26:07

Message: 1 of 6

Hello all,

I use eval to make matrixes, but it shows each result in Command Window.

For example, when I run the code as follows,

  for i=1:10
    A=[1,2,3;4,5,6];
    B=A*i;
    eval(['result' num2str(i) '=B']);
  end

the Command Window shows that
  result1 =

     1 2 3
     4 5 6

 result2 =

     2 4 6
     8 10 12

 result3 =

     3 6 9
    12 15 18
...............

Is there any method not to show the result in Command Window?

Subject: A problem about eval result in command window

From: Bruno Luong

Date: 30 May, 2012 06:42:09

Message: 2 of 6


> Is there any method not to show the result in Command Window?

At a semi-colon:

eval(['result' num2str(i) '=B;' ]);

As long as you use EVAL, your code will be slow and difficult to maintain.

Bruno

Subject: A problem about eval result in command window

From: Galam Lee

Date: 30 May, 2012 06:52:07

Message: 3 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jq4fg1$nf$1@newscl01ah.mathworks.com>...
>
> > Is there any method not to show the result in Command Window?
>
> At a semi-colon:
>
> eval(['result' num2str(i) '=B;' ]);
>
> As long as you use EVAL, your code will be slow and difficult to maintain.
>
> Bruno

Firstly, Thank you for your reply :)
I already used semi-colon, but the problem was not solved... :(

Subject: A problem about eval result in command window

From: Bruno Luong

Date: 30 May, 2012 07:02:08

Message: 4 of 6

"Galam Lee" wrote in message <jq4g2n$306$1@newscl01ah.mathworks.com>...

> I already used semi-colon, but the problem was not solved... :(

A screen shot of mine:

>> for i=1:10
    A=[1,2,3;4,5,6];
    B=A*i;
    eval(['result' num2str(i) '=B;']);
  end
>>

% Bruno

Subject: A problem about eval result in command window

From: Galam Lee

Date: 30 May, 2012 07:28:05

Message: 5 of 6

> A screen shot of mine:
>
> >> for i=1:10
> A=[1,2,3;4,5,6];
> B=A*i;
> eval(['result' num2str(i) '=B;']);
> end
> >>
>
> % Bruno

I find the cemi-colon behind B;.
I really apreciate your reply!

Best reagrds,
Galam Lee

Subject: A problem about eval result in command window

From: Steven_Lord

Date: 30 May, 2012 13:35:25

Message: 6 of 6



"Galam Lee" <lee.galam@gmail.com> wrote in message
news:jq4i65$av6$1@newscl01ah.mathworks.com...
>> A screen shot of mine:
>>
>> >> for i=1:10
>> A=[1,2,3;4,5,6];
>> B=A*i;
>> eval(['result' num2str(i) '=B;']);
>> end
>> >>
>>
>> % Bruno
>
> I find the cemi-colon behind B;.
> I really apreciate your reply!

Glad you found that, but IMO your code still has a problem. As Bruno said,
you should NOT use EVAL in this way. Use one of the alternatives given in
question 6 in the Programming section of the FAQ instead.

http://matlab.wikia.com/wiki/FAQ

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us