octave-maintainers
[Top][All Lists]
Advanced

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

Re: line continuations


From: Nicholas Jankowski
Subject: Re: line continuations
Date: Thu, 20 Feb 2020 12:10:07 -0500

On Thu, Feb 20, 2020 at 11:51 AM José Abílio Matos <address@hidden> wrote:
On Thursday, 20 February 2020 14.35.19 WET Nicholas Jankowski wrote:
> can you give a code example of what produces an error in matlab but not
> octave? i may be misunderstanding your earlier comments.

c = ['1 2 3 '; '4 5 6 ']

strrep(c, '2', '0')

The call to strrep fails in Matlab since c is not a char array and it succeeds
in Octave (with an anti-intuitive result IMHO). My proposal is to do the same
in Octave.

[m,n] = size(c);

If m != 1 and n!= 1 then throw an error. I hope that this now makes sense. :-)


ok, it is a char array, so I was confused.  testing in matlab 2019a:
>> c = ['1 2 3';'4 5 6']

c =

  2×5 char array

    '1 2 3'
    '4 5 6'

>> strrep(c,'2','0')
Error using strrep
Char inputs must be row vectors.


so the problem isn't that it is or isn't a char array.  the problem is that matlab only accepts character vectors.  any arrays must either be string or cell arrays. (and Octave doesn't do strings yet).

It's generally not a bug for Octave to have capability that extends beyond Matlab, which is what appears to be the case here.  multidimensional arrays are always stored column-wise (despite most of us reading row-wise), and that's no different here. 

I see no reason to throw an error, unless you see lack of an error message causing some other problem? 

The only possible issue is that it doesn't return the original shape.  But then strrep doesn't require substituted strings preserve length, so there's no way it can preserve array shape by default. 

e.g., 
octave:7> strrep(c,'2','0000')
ans = 14  00005  36


 

reply via email to

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