[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sprintf help
From: |
rik |
Subject: |
Re: sprintf help |
Date: |
Fri, 15 May 2015 08:56:07 -0700 |
On 05/15/2015 08:19 AM, John W. Eaton wrote:
> On 05/15/2015 12:53 AM, rik wrote:
>
> > Could someone run the following code under Matlab?
> >
> > -- Begin Code --
> > x = sprintf ('%s%s%s\n', [65 66 67])
> > size (x)
> >
> > y = sprintf ('%s %s%s\n', [65 66 67])
> > size (y)
> > -- End Code --
> >
> > Octave returns 1x3, i.e., missing the newline character. Unless there is
> > something after the first '%s' in the format specification such as a
> space.
>
> The [65, 66, 67] matrix is a single argument and is converted to a string
> for printing here and the %s converts the entire string. When you add
> the space, Y should contain "ABC ". Since there are no further arguments
> to convert after the first, the rest of the format is skipped. Isn't
> that the correct behavior?
>
> jwe
>
Yes, this is the correct behavior. sprintf() appears to be 100% compatible
with Matlab.
I was investigating num2str, and indirectly sprintf since it is used
internally, and there are some minor differences with num2str which I will
file a bug report on.
--Rik