Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find first zero in array in matlab [closed]

Tags:

matlab

I want to find first zero element in array in matlab. I'm using "find" function to find zero but it didn't giving true answer but it give correct answer for 1.

like image 461
Malik Avatar asked Dec 13 '22 03:12

Malik


2 Answers

find should do the trick if used like so:

> a = [1 2 3 0 5 6 0 8 9];
> find(a==0, 1, 'first')
ans =  4

Let us know if this isn't working (and some additional details about the problem).

MATLAB find

like image 91
Jonathan Fretheim Avatar answered Dec 28 '22 19:12

Jonathan Fretheim


>> a = [1 2 3 0 5 6 0 8 9];

>> a=a==0;

>> n=1:length(a);

>> [n out]=max(a./n);

out =

     4
like image 38
veeresh Avatar answered Dec 28 '22 19:12

veeresh