hi, if i have array=[89 130 150 180...],in 1st iteration i need to perform "1:array(1)",in 2nd iteration i need "array(1)+1 :array(2)",in 3rd iteration i need "array(2)+1 :array(3)" and so on,i tried a lot,plz help me

조회 수: 1 (최근 30일)
help plz

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 30일
편집: Walter Roberson 2015년 10월 2일
array=[89 130 150 180...]
tarray = [1 array];
for K = 1 : length(tarray)-1
tarray(K):tarray(K+1)
end
  댓글 수: 2
kaavya subramani
kaavya subramani 2015년 10월 1일
tarray(K) will not incremented to 90,131... in next next iteration
Walter Roberson
Walter Roberson 2015년 10월 2일
array=[89 130 150 180...]
tarray = [0 array];
for K = 1 : length(tarray)-1
tarray(K)+1:tarray(K+1)
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Julia
Julia 2015년 9월 30일
Hi,
my suggestion is:
do the first iteration outside the loop, the remaining can be done within:
1:array(1);
% do s.th.
for i=1:size(array)-1
(array(i)+1) : array(i+1);
% do s.th.
end

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by