Using a variable in a command insdie a function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using a variable in a command insdie a function

Edward C. Jones
I have a command inside a function. I want the command to depend on some
variable. Here is an ugly way to do it:

function silly
    filename = 'mess.asc';
    x = 77;
    s = ['save -ascii ' filename ' x'];
    eval(s);
endfunction

Is there a better way? Is there a function corresponding to the "save"
command?



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Using a variable in a command insdie a function

Brian Blais
Edward C. Jones wrote:

> I have a command inside a function. I want the command to depend on some
> variable. Here is an ugly way to do it:
>
> function silly
>    filename = 'mess.asc';
>    x = 77;
>    s = ['save -ascii ' filename ' x'];
>    eval(s);
> endfunction
>
> Is there a better way? Is there a function corresponding to the "save"
> command?
>

could you do the following?  is this what you want?

function silly
    filename = 'mess.asc';
    x = 77;
    save('-ascii',filename,'x');
endfunction




                                        bb

--
-----------------

             [hidden email]
             http://web.bryant.edu/~bblais



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------