help-octave
[Top][All Lists]
Advanced

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

Re: beginner: function definition confusion


From: Doug Stewart
Subject: Re: beginner: function definition confusion
Date: Thu, 21 Apr 2005 20:56:13 -0500
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Jeff Abrahamson wrote:

I'm confused trying to use nlfilter.  (The ultimate goal is to do
convolutions on images.)  I'm not sure if I'm misunderstanding
nlfilter or if I'm even maybe just defining the function avg
incorrectly.  Here's what I wrote

   function T1 ( )
     img = imread("black-white.png");
     blur = nlfilter(img,[3,3],avg)

blur = nlfilter(img,[3,3],avg(you must put something here)  )



   endfunction


   function ret = avg ( blk )
     ret = 0;
     for i = 1:3
        for j = 1:3
          ret += blk(i,j);
        endfor
     endfor
     ret /= 9;
   endfunction

   T1()


The error is this:
 octave:1> T1()
 error: `blk' undefined near line 22 column 14
 error: evaluating assignment expression near line 22, column 11
 error: evaluating for command near line 21, column 5
 error: evaluating for command near line 20, column 3
 [...]

Anyone see what I'm doing wrong?


Note, by contrast, that avg works in the form I thought I needed it
to:

 octave:1> m=rand(3)
 m =

   0.30486  0.74804  0.28817
   0.54096  0.62247  0.70384
   0.67811  0.58588  0.38752

 octave:2> avg(m)
 ans = 0.53998
octave:3>
Thanks in advance.




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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