[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Empty matrices
From: |
John W. Eaton |
Subject: |
Empty matrices |
Date: |
Wed, 15 Oct 2008 14:08:44 -0400 |
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.
| How to proceed?
Fix your code.
| Or is this a bug in octave?
I don't think so.
jwe
- Empty matrices, LUK ShunTim, 2008/10/15
- Empty matrices,
John W. Eaton <=