send octave output to string

Ben Abbott bpabbott at mac.com
Sun Sep 7 18:38:16 CDT 2008


On Sep 7, 2008, at 7:17 PM, Bill Denney wrote:

> charles reid wrote:
>> Hi there -
>>
>> I've been searching Octave documentation & the web with no luck on
>> this, so I thought I would ask here.  If I want to send the output of
>> an Octave command to a string, how would I do that?  For example,  
>> if I
>> type
>>
>>>> a = 2 + 2
>>
>> And I want a string to contain the resulting " a = 4 ", how would I  
>> do
>> that?  Thanks!
>
> You're looking for num2str or sprintf:
>
> num2str(a)
>
> or
>
> spritnf("%d", a)
>
> Have a good day,
>
> Bill

If you want the "a =" part as well.

str = sprintf ("a = %d", a);

Or do you want to capture the output to the console for a specific  
command?

I dont' know how to do that, anyone else?

Ben



More information about the Help-octave mailing list