octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #37390] In matlab repmat can have empty inputs


From: Richard
Subject: [Octave-bug-tracker] [bug #37390] In matlab repmat can have empty inputs
Date: Sat, 22 Sep 2012 10:01:17 +0000
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.3) Gecko/20100101 Firefox/10.0.3

Follow-up Comment #3, bug #37390 (project octave):

Incidentally, there are further differences in behaviour, for example the
following in ML:

>> repmat(1, [2,2], 3)

ans(:,:,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,3) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000

>> repmat(1, [2,2], 3, 3)
Error using repmat
Too many input arguments.
 
>> repmat(1, [2,2,2], 3)

ans(:,:,1,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,1,2) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,2) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,1,3) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,3) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000

>> repmat(1, [2,2,2], [3,3])

ans(:,:,1,1,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,1,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,1,2,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,2,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000
... lots more output

So it seems m and n need not be scalar in ML, the dimensions are in fact just
tacked onto each other. This is consistent with what was seen with empty
inputs. Therefore you could get rid of the error and just do something like:

# check second arg first so it will be one if both
# m and n are empty
if (isempty (n))
n = 1;
endif
if (isempty (m))
m = n;
n = 1;
endif

if isvector(m) && isvector(n)
idx = [m(:)',n(:)'];
else
error('M and N must be scalars or vectors')
endif


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?37390>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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