help-octave
[Top][All Lists]
Advanced

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

Re: Empty matrices


From: LUK ShunTim
Subject: Re: Empty matrices
Date: Fri, 17 Oct 2008 11:07:42 +0800
User-agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724)

John W. Eaton wrote:
> On 15-Oct-2008, LUK ShunTim wrote:
> 
> | Hi,
> | 
> | This snippet is taken from some matlab code:
> | 
> | fd=inline('sqrt(sum(p.^2,2))-1','p');
> | 
> | p=[0.01 0.00; -0.51 -0.05; 0.01 -0.20] % NG!
> | %p=[1.01 0.00; -0.51 -0.05; 0.01 -0.20] % Works
> | %p=[1.01 0.00; -1.51 -0.05; 0.01 -1.20] % Works
> | 
> | d=feval(fd, p)
> | ix=d>0
> | a=d(ix)
> | 
> | val=0.05;
> | b=feval(fd, [p(ix,1)+val, p(ix,2)])
> | 
> | res=b-a
> | 
> | It works when ix returns at less one non-zero index but fails if ix=0.
> | The result of using p=[0.01 0.00; -0.51 -0.05; 0.01 -0.20] is:
> | 
> | ix =
> | 
> |    0
> |    0
> |    0
> | 
> | a = [](0x0)
> | b = [](0x1)
> | error: operator -: nonconformant arguments (op1 is 0x1, op2 is 0x0)
> | error: evaluating binary operator `-' near line 14, column 6
> | 
> | I cannot claim that the matlab code works as I've no matlab installed to
> | do the test, though. :-(
> 
> I think the dimensions must always conform unless one of the operands
> is a scalar, in which case the operation with the scalar is applied
> to all elements of the non-scalar operand.

Thanks for you reply, John. I guest my problem is the p(ix,1) and
p(ix,2). This is something that I don't understand. Consider this:

octave:1> a=[1, -1]
a =

   1  -1

octave:2> ix=a>10
ix =

   0   0

octave:3> a(ix,1)
ans = [](0x1)

I don't understand the (0x1) after the empty matrix. I would have
thought that it shouldn't work, like a(0,1) in the next line.

octave:4> a(0,1)
error: invalid row index = 0

And I don't see how to create it:

octave:4> emt=[]
emt = [](0x0)
octave:5> emt2=[ , ]
parse error:

  syntax error

>>> emt2=[ , ]
            ^

octave:5> emt2=[[],[]]
emt2 = [](0x0)
octave:6> emt2=[[],]
emt2 = [](0x0)

Still (0x0).

Please enlighten.

Regards,
ST
--


reply via email to

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