Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Script is causing error
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a piece of code that is being repeated in several routines, however I cannot make a function of it since it should changes inputs which is varargin. So the solution seems to put the piece of code in a m file and mention the name in calling routines. When I move the code to a file and call it, all the variables will be exactly the same way as if it is the body of code, however a calling function that comes after the script returns error: "Too many output arguments" when I put the script in the body, this error is not showing up anymore!!!
the code is:
function varargout=batchMean(func,adrs,varargin)
% code I want to move to script file
grd=find(strcmp(varargin,'grid'));
grdfl=find(strcmp(varargin,'gridFile'));
if grd
% If grid is provided in the arguments
grid=varargin{grd+1};
varargin(grd:grd+1)=[];
elseif grdfl
grdFile=cellstr(ls([adrs varargin{grdfl+1} '*']));
varargin(grdfl:grdfl+1)=[];
if isempty(grdFile)
error('Hall_lab:batchAV:argin', ...
'Grid file mentioned in input could not be found');
end
[grid,err]=matRead([adrs grdFile{1}]);
if err
error('Hall_lab:batchAV:grid', ...
'Could not read grid file');
end
else
% Reading grid file
grdFile=cellstr(ls([adrs '*Grd.mat']));
if isempty(grdFile)
grdFile=cellstr(ls([adrs '*grd.mat']));
end
if length(grdFile)>1
error('Hall_lab:batchAV:fileSet', ...
'There is more than one file for grid');
elseif isempty(grdFile{:});
error('Hall_lab:batchAV:fileSet', ...
'There is no file for grid');
end
[grid,err]=matRead([adrs grdFile{:}]);
if err
error('Hall_lab:batchAV:grid', ...
'Could not read grid file');
end
files=setdiff(files,grdFile);
end
% end of code I want to move to script file
% calling the function
[out{1:outNums}]=func(grid,data,inf,varargin{:});
% actuall function being called
function [ave]=meanPIV(~,data,~)
ave=mean(data,ndims(data));
end
0 Commenti
Risposte (1)
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!