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!