help-octave
[Top][All Lists]
Advanced

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

indexing problem? arrayfun


From: ernst
Subject: indexing problem? arrayfun
Date: Sun, 10 Feb 2013 22:23:29 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120825 Thunderbird/15.0

Hi all,
since i want to have arrayfun for general classes, i reimplemented
arrayfun (see below).
But it does not work for dimensions >2.
Do I sth. wrong with indexing??
Also i wonder whether there is a non-recurseive solution?

Any hints?

greetings,

Ernst





function res = arrayfun(funcScal, arr)

  %% if funScal is a string replace by according inline function
  if ischar(funcScal)
    funScal = inline(funScal);
  end

  %% Exclude that funcScal is something but a function handle
  if ~isa(funcScal,'function_handle')
    error('arrayfun: argument NAME must be a string or function handle');
  end
  assert (isa(funcScal,'function_handle'));


  %% Here, arr is not scalar
  assert (length(size(arr)) >= 2);

  if length(size(arr)) == 2
    for idx1 = [1:size(arr)(1)]
      for idx2 = [1:size(arr)(2)]
    res(idx1,idx2) = feval(funcScal, arr(idx1,idx2));
      end
    end
    return;
  end

  for idx = [1:size(arr)(1)]
    res(idx,:)=arrayfun(funcScal,arr(idx,:));
  end
endfunction



reply via email to

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