Find the first zero in an array in matlab

Please help me. I want to find the first null element in an array in matlab. I use the find function to find zero, but it did not give a true answer, but it gives the correct answer for 1. so please help me as soon as possible.

+5
source share
3 answers

find should do the trick if used like this:

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

Let us know if this does not work (and some additional information about the problem).

MATLAB find

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

>> a=a==0;

>> n=1:length(a);

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

out =

     4
+1
source

more simple:

find(~a,1,'first')
0
source

All Articles