[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with m-file
From: |
Peter Cloetens |
Subject: |
Re: problem with m-file |
Date: |
Fri, 24 Nov 2006 15:48:45 +0100 |
Hello Marco,
This must be a typing error. When I copy your code from the message to
an m-file it works perfectly.
Maybe you have
for x=i:m or for y=i:n
in your file (complex number i).
By the way, you should avoid loops to be faster, just use:
s=sum(A(:))
Peter
On Fri, 2006-11-24 at 14:43 +0100, Marco Hippler wrote:
> Hi @ll
> i've installed octave on my debian via aptitude.
> Now my problem:
> i've written an m-file test1.m
>
> %m File
> function summe=test1(A)
> [m,n]=size(A);
> summe=0;
> for x=1:m
> for y=1:n
> summe=summe+A(x,y);
> end
> end
>
>
> than given A the values:
>
> A=[1 2;3 4]
>
> and finally:
>
> s=test1(A)
>
> but it doesn't work:
>
> error: complex scalar type invalid as index value
> error: evaluating binary operator `+' near line 6, column 14
> error: evaluating assignment expression near line 6, column 8
> error: evaluating for command near line 5, column 2
> error: evaluating for command near line 4, column 1
> error: called from `test1' in file `/usr/share/octave/2.1.69/m/FH/test1.m'
> error: evaluating assignment expression near line 16, column 2
>
> let's have a look at the variables x&y
> octave:16> x
> error: `x' undefined near line 16 column 1
> octave:16> y
> error: `y' undefined near line 16 column 1
> hmmm??????
>
> then i've tried running it line by line in the promt and it works fine:
>
> [m,n]=size(A)
> m = 2
> n = 2
> summe = 0
> octave:6> for x=1:m
> > for y=1:n
> > summe=summe+A(x,y)
> > end
> > end
> summe = 1
> summe = 3
> summe = 6
> summe = 10
>
> so i think there's a basic problem with octave, does anybody have an idea??
> (By the way, the m-file is from my professor and it works fine with Matlab in
> windows) :-(
>
> _______________________________________________________________________
> Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und kostenlos.
> Gleich testen! http://www.pc-sicherheit.web.de/freescan/?mc=022222
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>