I have a function which takes 11 pairs of input arguments (each pair representing a type of process and an input commodity) and calculates a result based on all of those 22 values. However, I would like to make the function flexible such that if I wanted to use, for example, 3 pairs of input arguments rather than 11, it would still come up with a result and meanwhile ignore the other 8 pairs of unused arguments. Can you please tell me the simplest way to do that?
I've tried using varargin but when I pass fewer than 22 values as the input arguments, MATLAB tells me that the 'the (varargin) index (in the function file) exceeds the marix dimensions.'
Is there any way to pass 'inactive' input arguments so that MATLAB simply doesn't perform any operation on them?
Thanks.
Here's a sample of my code in the function file:
function [ Eprout,AnnEprout,Demand,AnnDemand,Status,AnnStatus ] = supdem(time, country, weights,supdataset,output, demdataset,... process1,process2,process3,process4,process5,process6,process7,process8,process9,process10,process11,... ipcom1,ipcom2,ipcom3,ipcom4,ipcom5,ipcom6,ipcom7,ipcom8,ipcom9,ipcom10,ipcom11)
Eprout = (sum(sum(supdataset(time,country,process1,ipcom1,output)))+sum(sum(supdataset(time,country, process2,ipcom2,output)))+ ... sum(sum(supdataset(time,country,process3,ipcom3,output)))+sum(sum(supdataset(time,country, process4,ipcom4,output)))+ ... sum(sum(supdataset(time,country,process5,ipcom5,output)))+sum(sum(supdataset(time,country, process6,ipcom6,output)))+... sum(sum(supdataset(time,country,process7,ipcom7,output)))+sum(sum(supdataset(time,country, process8,ipcom8,output)))+ ... sum(sum(supdataset(time,country,process9,ipcom9,output)))+sum(sum(supdataset(time,country, process10,ipcom10,output)))+... sum(sum(supdataset(time,country,process11,ipcom11,output))))/1000;
vararginsounds like the way to go indeed. Can you show the code that triggers the "index exceeds matrix dimensions" error? - Eitan T