SIMPLIFY FOR LOOP - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

SIMPLIFY FOR LOOP

AkimaAkima Posts: 2Member
HELOO, I TRIED TO SIMPLIFY FOLLOWING:

sp=1:4;
ep=1:4;
for k=1:length(m4)
if m4(k)>0
return
end
sp(1)=k;
end
for k=sp(1)+1:length(m4)
if m4(k)==0
return
end
ep(1)=k+1;
end
for k=ep(1)+1:length(m4)
if m4(k)>0
return
end
sp(2)=k;
end
for k=sp(2)+1:length(m4)
if m4(k)==0
return
end
ep(2)=k+1;
end
for k=ep(2)+1:length(m4)
if m4(k)>0
return
end
sp(3)=k;
end
for k=sp(3)+1:length(m4)
if m4(k)==0
return
end
ep(3)=k+1;
end
for k=ep(3)+1:length(m4)
if m4(k)>0
return
end
sp(4)=k;
end
for k=sp(4)+1:length(m4)
if m4(k)==0
return
end
ep(4)=k+1;
end

!!!!TO THIS:
sp=1:4;
ep=1:4;
for k=1:length(m4)
if m4(k)>0
return
end
sp(1)=k;
end
for k=sp(1)+1:length(m4)
if m4(k)==0
return
end
ep(1)=k+1;
end
for j=2:4
for k=ep(j-1)+1:length(m4)
if m4(k)>0
return
end
sp(j)=k;
end

for l=sp(j)+1:length(m4)
if m4(l)==0
return
end
ep(j)=l+1;
end
end
BUT IT DID NOT WORK. CAN ANYONE TELL WHERE I AM MAKING MISTAKE????
THANKS

Sign In or Register to comment.