2

嵐の期間を決定するために、特定の嵐のすべての観測と複数の嵐の間のハリケーン観測間の連続した時間 (変数 'hrs') を累積的に合計しようとしています。これは私が持っているものです:

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 も試しましたが、ストーム ID が同じ場合にのみ cumsum を使用する方法がわかりませんでした。

誰かに何かアイデアがあれば、大歓迎です!ありがとう。

4

2 に答える 2

0

これは機能しますか?

編集:コメントするのに十分なポイントがないため、ここで提案されたコードを変更しました。(期間が十分に広くないためにエラーが発生すると仮定して正しいですか?)

clear duration
unique_storm_id = unique(stormid);
duration = zeros(length(unique_storm_id),length(hrs));
for k = 1:length(unique_storm_id)
    duration{k} = cumsum(hrs(stormid == unique_storm_id));
end

次に、次を使用して嵐 id = j の期間にアクセスできます。

index = find(unique_storm_id == j);
duration{index}
于 2015-01-26T19:05:14.127 に答える