How to find the firs numeric data in varargin?

 Accepted Answer

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 Comments

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.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 16 Sep 2015

Commented:

on 16 Sep 2015

Community Treasure Hunt

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

Start Hunting!