help-octave
[Top][All Lists]
Advanced

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

How to prevent "error: A(I, J) = X: X must be a scalar..." with working


From: John W. Eaton
Subject: How to prevent "error: A(I, J) = X: X must be a scalar..." with working matlab code
Date: Tue, 31 Jul 2007 11:47:24 -0400

On 31-Jul-2007, address@hidden wrote:

| I'm  having  troubles  getting  working  matlab  code to be run with octave. I
| couldn't find an answer to my problem in the archive or the net  although  I'd
| say it should be quite popular.
| Anyway octave can't handel this:
| 
| u= linspace(0,1,P)
| x1(:,1)= 0.5.*(u)-0.5
| 
| It complains:
| error: A(I, J) = X: X must be a scalar or the number of elements in I must
| error: match the number of rows in X and the number of elements in J must
| error: match the number of columns in X
| error: assignment failed, or no method for `<unknown type> = matrix'
| 
| If  I  do x1(1,:)= 0.5.*(u)-0.5 all is fine. Having to rewrite the matlab code
| would be a pain. Is there an easier way to get it to work with octave?

Easier for whom?  You don't want to do a little work to fix your code
so you would rather have someone else do some work for you?  It would
also be a bit of a pain to "fix" Octave to make your code work.

I am not interested in adding another special case to the indexed
array assignment code and after all these years I still don't
understand precisely what the rules are for matching up dimensions
with colon indices when the array on the left hand side is undefined
prior to the assignment.  If someone can clearly explain what the
rules are, maybe Octave could be compatible.  Does anyone know of
documentation for this Matlab feature, or is it just something that
people come to understand in some sort of mystical way?

BTW, I think it is more complex than just saying that if the RHS is a
vector, the colon is the length of the vector.  For example, compare
these assignments:

  x(1,:,:) = [1, 2, 3]

    ==>  x(:,:,1) = 1
         x(:,:,2) = 2
         x(:,:,3) = 3


  x(1,:,:,:) = [1, 2, 3]

    ==>  [1, 2, 3]


  x(1,:,:) = [1; 2; 3]

    ==>  [1, 2, 3]


  x(1,:,:,:) = [1; 2; 3]

    ==>  [1, 2, 3]


(with X undefined before the assignment).  Maybe it's just me, but I'm
failing to see the pattern or logic here.

jwe


reply via email to

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