I want my function to use default values if no input variables are passed. I have done this in the past using the 'nargin' function. I prefer this approach to using the 'isempty' function. For some reason my code now returns an error when I only input 't' because the varargin{} arrays are technically empty. This error makes sense, but I don't understand how to get around it as I thought the if/else statements would take care of that. How can I debug this?
Error: Index exceeds the number of array elements (0).
function [V, varargout] = HH(t, varargin)if nargin < 1 V0 = -60;else V0 = varargin{1};endif nargin < 2 I = 0;else I = varargin{2};end
Best Answer