[Top][All Lists]

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

beginner: function definition confusion

From: Jeff Abrahamson
Subject: beginner: function definition confusion
Date: Thu, 21 Apr 2005 21:35:07 -0400
User-agent: Mutt/1.5.6+20040907i

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)

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


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

  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

Thanks in advance.


 Jeff Abrahamson  <>    +1 215/837-2287
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

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

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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