Fill array with values of other array from index1 to index2
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello! I have one array (one double column) DateN which contains 21000 values that represent 6 months of dates and time. However I would like to have another array (one double column) that would start at a specific date and end on another (index1 and index2). I tried this code but it freezes matlab and have to restart it (i understand why now)
v=index2-(index1-1);
for g1=1:v
for g2=index1:(index2-1)
global Temps
Temps(g1,1)= DateN(g2,1);
g1=g1+1;
g2=g2+2;
end
end
and I tried this code:
g2=1;
for g1=index1:index2
Temps(g2,1)= DateN(g1,1);
g1=g1+1;
g2=g2+1;
end
But instead of getting index2-index1 values in Temps I get 3000 more values. Can anyone help? I am using R2013a. Thank you very much!
댓글 수: 0
채택된 답변
Jan
2017년 5월 30일
편집: Jan
2017년 5월 30일
Do you mean:
Temps = DateN(index1:index2, 1);
Using global 's is surely a bad idea. Avoid globals strictly to allow for an efficient debugging.
for g1=index1:index2
...
g1=g1+1;
end
You should get a warning in the editor: Modifying the loop counter inside the loop is meaningless. g1 is incremented by the FOR loop already.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!