help-octave
[Top][All Lists]
Advanced

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

Re: beginner: function definition confusion


From: Stefan van der Walt
Subject: Re: beginner: function definition confusion
Date: Sun, 24 Apr 2005 17:57:22 +0200
User-agent: Mutt/1.5.6+20040907i

Hi Jeff

Also consider the 'conv2' and 'fftconv2' functions from octave forge.

Stefan

On Thu, Apr 21, 2005 at 09:35:07PM -0400, 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)
>     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]