我试图在特定风暴和多次风暴中的所有观测值的飓风观测值之间连续累计累计小时数(变量'hrs'),以确定风暴的持续时间。这是我有:循环的累积总和matlab
stormid = [188, 188, 288, 288, 288, 388, 488, 488, 588...] %numbers represent a unique
% code identifying a particular storm (i.e. 188= 1st storm of 1988)
hrs = [0,6,0,6,6,0,0,6,0...] %hours between observations in each storm
% where 0 indicates the start of a storm (this corresponds with the stormid above)
我的目标是要总结的小时,每个风暴的ID,所以我想用accumarray会的工作,但事实并非如此。这是我试过的。
duration= accumarray(stormid, hrs, []);
然后,我也试过cumsum,但我无法弄清楚如何使用cumsum风暴id是相同的。
如果有人有任何想法,我将不胜感激!谢谢。
我想不出一个办法做到这一点整齐。 'accumarray'只能用于返回标量的函数,而不能用于矢量,所以它不能和'cumsum'一起使用。您可以随时手动循环浏览'stormid'和总结'hrs',每次您找到新的身份证号码时都会重新开始? – eigenchris 2015-01-26 18:46:09
那么'duration = accumarray(stormid,hrs,[]);'的错误信息是什么意思? '第二个输入VAL必须是一个向量,其中每个'** row **'在SUBS或一个标量中都有一个元素。如果你只是读了'doc accumarray'的第二个例子,你可能可以解决这个转置问题。 – knedlsepp 2015-01-26 19:24:48
作为一个旁注:因为你的stormIDs不是连续的,而是使用'accumarray'和列向量,你应该使用'sparse',它也可以将这些值相加,但会为你节省一些内存(或者你可以转换ID在使用“独特”的预处理步骤中)。 – knedlsepp 2015-01-26 19:34:56