필터 지우기
필터 지우기

Using Function and rowfun

조회 수: 21 (최근 30일)
Stephen Fleming
Stephen Fleming 2021년 2월 16일
댓글: Stephen Fleming 2021년 2월 16일
Hi,
I'm trying to run this function through every row of a table to perform a calculation to get an output angle of sequence component analysis in an electrical transmission circuit. I am using rowfun to try and output the function but i keep getting an error.
Dtab=rowfun(@ZAngle, SequenceTable, 'OutputVariableName', 'ZeroAngle');
function Azero = ZAngle(Vzr, Vzi)
if Vzr<0 && Vzi>0
Azero=180-((atan(abs(Vzi)/abs(Vzr)))*180/pi);
end
if Vzr>0 && Vzi<0
Azero=-(atan(abs(Vzi)/abs(Vzr))*180/pi);
end
if Vzr<0 && Vzi<0
Azero=-180+((atan(abs(Vzi)/abs(Vzr)))*180/pi);
end
if Vzr>0 && Vzi>0
Azero=(atan(abs(Vzi)/abs(Vzr)))*180/pi;
end
end
With 'Dtab' being the output table that i want, 'ZAngle' being the function name, the 'SequenceTable' being the table i am taking values from, and 'Vzi' and 'Vzr' being the column headings of values i want to input to the function from the table (These are real and imaginary parts of numbers in cartesian form) and Azero being the desired output.
There is 99000 rows of data in the table and i want to perform this calculation on each row of data.
I am getting this error:
Error using tabular/rowfun>dfltErrHandler (line 517)
Applying the function 'ZAngle' to the 1st row of A generated the following error:
Too many input arguments.
Error in tabular/rowfun>@(s,varargin)dfltErrHandler(grouped,funName,s,varargin{:}) (line 262)
errHandler = @(s,varargin) dfltErrHandler(grouped,funName,s,varargin{:});
Error in tabular/rowfun (line 282)
[b_data{igrp,:}] = errHandler(struct('identifier',ME.identifier, 'message',ME.message,
'index',igrp),inArgs{:});
Error in FinalMatrix (line 51)
Dtab=rowfun(@ZAngle, SequenceTable, 'OutputVariableName', 'ZeroAngle');
and when i put rowfun after the function definition i get:
Error: File: FinalMatrix.m Line: 70 Column: 1
Function definitions in a script must appear at the end of the file.
Move all statements after the "ZAngle" function definition to before the first local function
definition.
Any help is appreciated (sorry about this being long),
Thanks!

채택된 답변

Julian
Julian 2021년 2월 16일
You may need to set the 'InputVariables' parameter for rowfun to {'Vzr' 'Vzi' } to pass only these variables to your function. rowfun pays no attention to the names of your variables and will attempt to call the function with every variable in your table. That can only work when nargin(func) == width(tbl) when applying func to every row of tbl.
  댓글 수: 1
Stephen Fleming
Stephen Fleming 2021년 2월 16일
Thank you very much, that fixed it and is working now.
Much Appreciated!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by