help-octave
[Top][All Lists]
Advanced

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

Re: Few questions (convolutions, 'mapping', linspace)


From: John Eaton
Subject: Re: Few questions (convolutions, 'mapping', linspace)
Date: Mon, 16 May 94 14:14:13 EDT

address@hidden (Przemek Klosowski) wrote:

:  - I often find myself defining a function (y=fun(x)), and hoping to
:    be able to 'map' (in the LISP sense) the vectors/matrices with
:    this function, for instance to plot it.

Here's one way to do it, but it won't be very fast.

  function y = map (f, x)

  # Given a function y = f (x) that expects a scalar argument and
  # produces a scalar result, call it for each element of the matrix x
  # and return the corresponding matrix of values.

    if (nargin != 2)
      error ("usage: map (f, x)");
    endif

    if (! isstr (f))
      error ("map: expecting string as first argument");
    endif

    [nr, nc] = size (x);
    y = zeros (nr, nc);
    for j = 1:nc
      for i = 1:nr
        y (i, j) = feval (f, x (i, j));
      endfor
    endfor

  endfunction

It might be desirable to add this as a built-in function to speed it
up, but even then it won't be all that fast because it will require
multiple calls to a user-supplied function, which is fairly slow.

jwe


reply via email to

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