0
votes

I have an array called contin array like [10,100,1000], and I'd like to apply a function called transcontin to that array. I know that the way to do this is arrayfunc(@transcontin, contin), if there is only one input to the function.

But, the function transcontin takes three inputs: Temp, b, and H. And, I need it to pass the values of the array into the function transcontin as b.

But, I have to loop through values of Temp and H. These values of Temp and H stay the same throughout each application to contin.

How do I accomplish this? How do I do arrayfunc(@transcontin, contin) but pass in the other two parameters that do not come in as an array?

Example input: contin=[10, 100, 1000]

Function:

function result=transcontin(Temp,b,h)
   result=b+Temp^h;
end

Let's say I want to fix Temp and h, and pass the elements of the array in as b:

Temp=5;
h=(1/3);

The output, after I do something like this upon the suggestion from @Edric arrayfun(@b transcontin(Temp, b, h), contin), should be a vector transformed into:

[10+5^(1/3), 100+5^(1/3), 1000+5^(1/3)]

how to accomplish this?

1
Provide an example of input/output/intermediate matrices - Sardar Usama
if i understand your question, you have some fixed parameters but arrayfunneed array as input. You can use repmat in order to clone your parameters. Something like: arrayfun(@thefunction,contin,repmat(b,1000,1) if you have 1000 loops. - obchardon

1 Answers

0
votes

You can "bind" in the constant arguments to an anonymous function handle, something like this (I think):

out = arrayfun(@(x) transcontin(Temp, x, H), contin)

The first argument to arrayfun is the anonymous function handle - that syntax creates a function that takes a single argument as required by arrayfun, and "binds" in the constant values Temp and H. More in the doc here: https://uk.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html