I have a function in Matlab:
function [runs,balls]=batting(form,team_flag,weather_flag)
form
is a 1x13
array of doubles. The flags are just boolean. runs,balls
are just scalars. The function above does some complex mathematical simulation to arrive at its output values. Now i write a wrapper :
function [runs,balls]=wrapper1(form)
[runs,balls]=batting(form,false,false);
Then I write another wrapper:
function runs_vector=wrapper2(form_vector)
for i=1:size(form_vector,1)
form_cell{i}=form_vector(i,:);
end
runs_vector=cellfun(@wrapper1, form_cell)';
It must be evident as to what i am trying to achieve. I am trying to exploit the behavior of cellfun
for my custom-defined function batting
. The flag arguments need to be set to false here but in general they are varied in the project of which this is part of. So i could not disappear the flag inputs to the batting
function without writing an intermediate wrapper,i.e. wrapper1
. My question is if there is a less ugly or more smart way of doing this?
batting
, such that it takes an x 13
matrix as input, which makes both wrappers obsolete. – hbadertsn
times in the batting function. Rather i have done so using the wrappers. And this seems more elegant than the for loop method. I want to keep the complex math sim as a separate blackbox which i don't want to peep into let alone modify! – user_1_1_1cellfun
(and all the *funs) is slower than the explicit loop in almost all cases. – excaza