>> V= [1 5 8 0 5 2 0 2 1 0 0.6 12 0]
V1=V(V~=0)
n=length(V(V==0))
V =
1.0000 5.0000 8.0000 0 5.0000 2.0000 0 2.0000 1.0000 0 0.6000 12.0000 0
V1 =
1.0000 5.0000 8.0000 5.0000 2.0000 2.0000 1.0000 0.6000 12.0000
n =
4
V=[1 5 8 0 5 2 0 2 1 0 0.6 12 0];
[Vsin0 num0]=ex6(V)
function [Vsin0 num0]=ex6(V)
num0=0;
for i=1:size(V,2);
if V(i)==0;
num0=num0+1;
else
Vsin0(i)=V(i);
end
end
end
function [Vsin0, num0] = ex6(V)
Vsin0 = [];
num0 = 0;
for i=1:size(V,2)
if V(i) == 0
num0 = num0 + 1;
else
Vsin0 =[Vsin0 V(i)];
end
end
end
function [Vsin0 num0]=ex6(V)
num0=0;
k=1;
for i=1:size(V,2)
if V(i)==0
num0=num0+1;
else
Vsin0(k)=V(i);
k=k+1;
end
end
end
function [V, num0] = ex6(V)
num0 = 0;
for i = size(V,2):-1:1
if V(i) == 0
num0 = num0 + 1;
V(i) = [];
end
end
end