## i need to delete a zero from a single row 10 column vector

### Omar Almahallawy (view profile)

on 28 Apr 2019
Latest activity Edited by Image Analyst

on 28 Apr 2019

### Stephan (view profile)

how can i delete this first 0
1.0e+03 *
0 1.0794 0.9376 0.8301 0.7477 0.6838 0.5939 0.5366 0.4988 0.4732
so it would look like this
1.0e+03 *
1.0794 0.9376 0.8301 0.7477 0.6838 0.5939 0.5366 0.4988 0.4732

### Stephan (view profile)

on 28 Apr 2019

A = [0 1 2 3 0 5]
A = A(A~=0)

dpb

### dpb (view profile)

on 28 Apr 2019
Or, the other Matlab idiom you'll see is
A(A==0)=[];
Or, to answer the original question with the qualifier of "only first zero" in Stephan's example data,
A(find(A==0,1))=[];
as the other two will eliminate all zeros, not just first...
Omar Almahallawy

### Omar Almahallawy (view profile)

on 28 Apr 2019
Thnak you!!

on 28 Apr 2019
To delete the first zero entry ONLY:
A(find(A==0,1,'first'))=[];

### Image Analyst (view profile)

on 28 Apr 2019
Edited by Image Analyst

### Image Analyst (view profile)

on 28 Apr 2019

To delete only the FIRST zero (not all zeros) here is one way.
indexes = find(v == 0);
if ~isempty(indexes) % Only try to delete if we actually FOUND a zero!
v(indexes(1)) = []; % Do the deletion.
end

on 28 Apr 2019
v(indexes(1) = []; % Do the deletion.
^--- missed a paranthesis
Image Analyst

### Image Analyst (view profile)

on 28 Apr 2019
You're right - thanks - fixed.