Effacer les filtres
Effacer les filtres

Using Function and rowfun

24 vues (au cours des 30 derniers jours)
Stephen Fleming
Stephen Fleming le 16 Fév 2021
Commenté : Stephen Fleming le 16 Fév 2021
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
if Vzr>0 && Vzi<0
if Vzr<0 && Vzi<0
if Vzr>0 && Vzi>0
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,
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
Any help is appreciated (sorry about this being long),

Réponse acceptée

Julian le 16 Fév 2021
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 commentaire
Stephen Fleming
Stephen Fleming le 16 Fév 2021
Thank you very much, that fixed it and is working now.
Much Appreciated!!

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Tables dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by