Fill array with values of other array from index1 to index2
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jan
on 30 May 2017
Edited: Jan
on 30 May 2017
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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!