Optional Arguments in Function as Struct Input
I have a Matlab function with many optional arguments which I want to call with these arguments recursively… This is just a short example, my real code is much more complexe and I don’t want to share it here… I know that this function seems kind of nonesense.
function [out] = calculateHatches(vec, args)
arguments
vec
args.Limit = 0
args.Color = ‘red’
args.Time = ’12:00′
% (and many more argumnts)
end
% some calculations that give me out
out = []
if args.Limit==0
for i=1:10
nargs = args;
nargs.Limit = 1;
% n arguments might change here …
% calculateHatches(vec,’Limit’,nargs.Limit,’Color’,nargs.Color,’Time’,nargs.Time)
nout = calculateHatches(vec,nargs)
out = [out, nout]
end
end
end
However, this won’t work, is there a way to makt it work?
calculateHatches(vec,nargs)
But I have too many optional arguments that change over time of programming too much, that I don’t want to write it into the code. This would mean a lot of administration work.
calculateHatches(vec,’Limit’,nargs.Limit,’Color’,nargs.Color,’Time’,nargs.Time)I have a Matlab function with many optional arguments which I want to call with these arguments recursively… This is just a short example, my real code is much more complexe and I don’t want to share it here… I know that this function seems kind of nonesense.
function [out] = calculateHatches(vec, args)
arguments
vec
args.Limit = 0
args.Color = ‘red’
args.Time = ’12:00′
% (and many more argumnts)
end
% some calculations that give me out
out = []
if args.Limit==0
for i=1:10
nargs = args;
nargs.Limit = 1;
% n arguments might change here …
% calculateHatches(vec,’Limit’,nargs.Limit,’Color’,nargs.Color,’Time’,nargs.Time)
nout = calculateHatches(vec,nargs)
out = [out, nout]
end
end
end
However, this won’t work, is there a way to makt it work?
calculateHatches(vec,nargs)
But I have too many optional arguments that change over time of programming too much, that I don’t want to write it into the code. This would mean a lot of administration work.
calculateHatches(vec,’Limit’,nargs.Limit,’Color’,nargs.Color,’Time’,nargs.Time) I have a Matlab function with many optional arguments which I want to call with these arguments recursively… This is just a short example, my real code is much more complexe and I don’t want to share it here… I know that this function seems kind of nonesense.
function [out] = calculateHatches(vec, args)
arguments
vec
args.Limit = 0
args.Color = ‘red’
args.Time = ’12:00′
% (and many more argumnts)
end
% some calculations that give me out
out = []
if args.Limit==0
for i=1:10
nargs = args;
nargs.Limit = 1;
% n arguments might change here …
% calculateHatches(vec,’Limit’,nargs.Limit,’Color’,nargs.Color,’Time’,nargs.Time)
nout = calculateHatches(vec,nargs)
out = [out, nout]
end
end
end
However, this won’t work, is there a way to makt it work?
calculateHatches(vec,nargs)
But I have too many optional arguments that change over time of programming too much, that I don’t want to write it into the code. This would mean a lot of administration work.
calculateHatches(vec,’Limit’,nargs.Limit,’Color’,nargs.Color,’Time’,nargs.Time) arguments, functions, matlab MATLAB Answers — New Questions