3
votes

I have a matrix with rows of 4 integers, with an unspecified number of columns (depends on the text file).

I'm wanting to apply a function to each row of the matrix, independently. The function has 4 inputs, and 2 outputs.

I'm trying to use the arrayfun function to do this, but whenever I call the function, I get an error saying: "Not enough input arguments."

Here is the function call:

[gain,phase]=arrayfun(@(x) GainPhaseComp(B(x,1:4)), 1:size(B));

where b is an n by 4 matrix.

Here is the function:

function [gain,phase] = GainPhaseComp(InAmp,InPhase,OutAmp,OutPhase)

gain = 20*log10(OutAmp\InAmp);

phase = (OutPhase - InPhase);

end

Any help would be greatly appreciated!

1

1 Answers

0
votes

Your function GainPhaseComp has 4 input arguments, but you pass only 1 row vector. Vector with 4 elements is still one variable, not 4. You need either to change the function definition or split the vector elements.

1st option:

function [gain,phase] = GainPhaseComp(inputvector)
% function body

2nd option:

[gain,phase]=arrayfun(@(x) GainPhaseComp(B(x,1),B(x,2),B(x,3),B(x,4)), 1:size(B,1));