How to find the firs numeric data in varargin?

1 view (last 30 days)
How to find the firs numeric data in varargin?

Accepted Answer

Kirby Fears
Kirby Fears on 16 Sep 2015
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
Mr M.
Mr M. on 16 Sep 2015
what if varargin contains no numeric value?
Kirby Fears
Kirby Fears on 16 Sep 2015
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

Find more on MATLAB Compiler SDK in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!