Fill array with values of other array from index1 to index2

3 ビュー (過去 30 日間)
Christine Abou Nasr
Christine Abou Nasr 2017 年 5 月 30 日
編集済み: Jan 2017 年 5 月 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!

採用された回答

Jan
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by