MatLab - Applying a function to each row in a matrix

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

I want to apply a function to each row of the matrix independently. The function has 4 inputs and 2 outputs.

I try to use the arrayfun function for this, but whenever I call the function, I get an error: "There are not enough input arguments."

Here is the function call:

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

where b is the matrix n by 4.

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!

+3
source share
1 answer

GainPhaseComp 4 , . 4 - , 4. , .

1- :

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

:

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

All Articles