Help with commands varargin and switch
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
[EDIT: Mon May 16 20:51:23 UTC 2011 - Reformat - MKF]
Hello,
I am new to MATLAB and I am trying to understand the code given in the following paper (Matov et al 'Analysis of microtubule dynamic instability using a plus-end growth marker', Nature, 7, 761-768 (2010).
One of the codes uses command varargin and switch. Could someone please explain the use of these command in MATLAB.
Part of the code is given below %START
function [cutoffIndex, cutoffValue, sp, axesH] = cutFirstHistMode(varargin)
% goodDataIdx is used in case data contains nans
goodDataIdx = [];
% check for axesHandle
if ishandle(varargin{1})
axesH = varargin{1};
varargin(1) = [];
verbose = 1;
else
axesH = [];
end
switch length(varargin) - isscalar(varargin{end})
case 1 % data
doHistogram = 1;
data = varargin{1};
data = data(:);
%END. I have given only a part of this code.
Your help is truly appreciated.
Thanks.
0 Commenti
Risposta accettata
Matt Fig
il 16 Mag 2011
4 Commenti
Jan
il 18 Mag 2011
Be careful: "ishandle(varargin{1})=1" is not a comparison, but a standard bug. You want: "ishandle(varargin{1})==1". "if ishandle(varargin{1})" works also, because ISHANDLE replies a LOGICAL already.
"if X" with a numerical X (even an array!) means explicitely: "if all(X) && ~isempty(X)".
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!