Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Script is causing error

1 visualización (últimos 30 días)
Mahdi
Mahdi el 16 de Jun. de 2014
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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

Respuestas (1)

Mahdi
Mahdi el 18 de Jul. de 2014
I'm struggling with this for a long time, can't anyone help please?

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by