help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help, answers showing in command prompt even though semicolon is use


From: Ben Abbott
Subject: Re: Help, answers showing in command prompt even though semicolon is used in if statement
Date: Tue, 30 Aug 2011 20:42:53 -0400

On Aug 30, 2011, at 8:09 PM, strugglinscientist wrote:

> What am I doing wrong? I do not want to be shown the answers
> 
> Here is my code
> if(amIOne==1 && amITwo==2 && amIThree==3)
>               {
>                       dataForZero=[dataForZero dataQZero];
>                       dataForOne=[dataForOne dataQOne];
>               }
>       end
> 
> Which results in the following in the octave prompt
> 
> ans=
> {
> [1,1]=-709
> [2,1]=-452
> }
> 
> Yet if I have the following code anywhere outside the if statement 
> 
> 
>                       dataForZero=[dataForZero dataQZero];
>                       dataForOne=[dataForOne dataQOne];
> 
> The answers are NOT posted to my prompt. How can I leave those inside the if
> statement and not have the answers show up in my prompt? Running through a
> lot of data...
> 

The syntax below ...

        a = {1; 2}

... creates a 2x1 cell array. The syntax below is equivalent.

        a = [
        {
        1;
        2;
        }
        ]

What you've done by inclosing the statements in curly braces is create a cell 
array which has been stored in the *default* variable named "ans". 

Another illustrative example is below ...

        {
        "a";
        pi;
        };

... after these commands nothing is posted to the prompt, but if you then type 
"ans" ....


        ans
        ans = 
        {
          [1,1] = a
          [2,1] =  3.1416
        }

Make sense?

Ben






reply via email to

[Prev in Thread] Current Thread [Next in Thread]