Thanks to everyone who has chimed in. It's much appreciated. And although I haven't found/implemented a solution yet, but I'll post my solution once I get there. Definitely a learning experience.
Step loop forward 10 units of a vector every iteration
7 次查看(过去 30 天)
显示 更早的评论
* UPDATE: To help clarify, I'm zooming out on my original problem. I have a long timeseries (OCS_d41) of 1/Hz data along a time vector (doyall) for which I would like to get hourly averages over 10-day intervals. I would then like to step forward to the next ten days along doyall and do the same thing, until the end of the timeseries. *
Within a loop, I need to break a vector (doyall, which begins at 138), into units of 10 through the length of the vector and apply a transformation (consolidator is the name of the plug-in script), and then save it out as a newly named vector.
The first iteration should cover 138: < 148. The second iteration should cover 148: < 158. The third iteration should cover 158: < 168, etc.
I don't know how to phrase the code so that it's applying the transformation within the loop only to chunks of 10 units of the vector at a time, then stepping forward to the next 10 units of the vector. Here is the code I have so far:
for doyall=138:(138+9):length(doyall);
itcount=itcount+1;
[hourallC, strcat('OCS_d41C_',num2str(itcount,'%02i'))]=consolidator(hourall, OCS_d41, 'nanmean', 0);
end
Thanks everybody. I appreciate it.
采纳的回答
更多回答(2 个)
Guillaume
2016-10-6
As pointed out by Dr Siva, if you want a step of 10, you just write that as the step in the for loop
The main issue is with your:
[..., strcat('OCS_d41C_',num2str(itcount,'%02i'))] = ...
It looks like you're trying to create numbered variables in your loop. This is an EXTREMELY bad idea, so I won't even tell you how to do it. It makes debugging very hard, the loop very slow and complicates the code tremendously.
Since all the variables are related, you simply stuff them all together into a container (cell array or matrix) and access each one with simple indexing.
Now here, I would show you how to solve your question, but unfortunately, in your example there is nothing that actually depends on the doyall chunks (it does not appear in the call to your consolidator function), so I've no idea what you're actually trying to do.
Also, is it guaranteed that the vector can be broken up in multiple of 10 with no leftover?
4 个评论
Steven Lord
2016-10-6
If you're using release R2016b I suggest storing your data in a timetable array and using the retime function to compute the hourly averages; see the first two examples on the retime documentation page linked above for a demonstration of how to do that.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Feature Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!