[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with arrayfun and parameter dimensions
From: |
Christoph Mahnke |
Subject: |
Problem with arrayfun and parameter dimensions |
Date: |
Fri, 07 Oct 2011 12:05:46 +0200 |
Hello everybody,
I want to avoid for-loops when applying a function on a matrix of
values, so my idea is to choose arrayfun.
A problem arises, as the function expects input parameters with
different dimensions, here as a simplified example:
function result = dummyfunction( x, parameter1, parameter2)
result = x * parameter1 - sum(x ./ parameter2 );
endfunction
where parameter1 is a simple number and parameter2 is a (fixed-length
1xN) vector.
I want to apply arrayfun on a array X of values, but i'm not sure how
to create a suitable array for the vector parameter. Some simple code to
illustrate my problem:
%
% for a single value
%
x1 = rand()
parameter1 = 7
parameter2 = 1:10
result1 = dummyfunction(x1,parameter1,parameter2) % (works well)
%
% this time a matrix
%
X=rand(3,4)
p1array= parameter1 * ones( rows(X), columns(X));
p2array= ???
R = arrayfun(@dummyfunction, X, p1array, p2array)
Maybe you can give me a hint how i have to create the parametermatrix
p2array to use in arrayfun.
Thanks, Christoph
- Problem with arrayfun and parameter dimensions,
Christoph Mahnke <=