How to find the firs numeric data in varargin?

 Akzeptierte Antwort

Kirby Fears
Kirby Fears am 16 Sep. 2015

1 Stimme

If the below code is not the answer you want, please elaborate on your question.
function MrM(varargin)
firstnum=find(cellfun(@(s)isnumeric(s),varargin),1,'first');
disp(firstnum);
end

2 Kommentare

Mr M.
Mr M. am 16 Sep. 2015
what if varargin contains no numeric value?
Then firstnum is empty. You can use
isempty(firstnum)
to know if numerical input was provided or not. You can use error handling like
if isempty(firstnum),
error('MrM() requires at least one numerical input');
end
Hope this helps.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Linear Algebra finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Sep. 2015

Kommentiert:

am 16 Sep. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by