transition probability matrix and for loop

5 ビュー (過去 30 日間)
Aleksandar
Aleksandar 2024 年 1 月 31 日
コメント済み: Voss 2024 年 2 月 1 日
I would like to run transition matrix with a rolling window, such that it ensures the transitions for consecutive periods such as: 31-12-17 (start date) to 31-12-18, then move by one month : 31-01-18 (start date) to 31-01-19 and so on, and save data in each transMat so that it can be retrieved later
That is what works
"transMatRD = zeros(5);
UD=unique(data.Date,'stable');
UD=sort(UD);
for i=1:25
[transMatRD] = transprob(data,'startDate',UD(i),'endDate',UD(i+12),'algorithm',algorithm,'snapsPerYear',snaps,'labels',{'A','B','C','D','E'})
disp(['The initial date: ',string(sUD3(i)),' the end date: ',string(sUD3(i+12)), 'transitions: ', string(snaps)])
end"
This works fine if I run it but I cannot save all transMatRD matrices (other than the last one).
If I try this however
"
for i=1:25
[transMatRD(i)] = transprob(data,'startDate',UD(i),'endDate',UD(i+12),'algorithm',algorithm,'snapsPerYear',snaps,'labels',{'A','B','C','D','E'})
"
I get this error:
"Unable to perform assignment because the left and right sides have a different number of elements."
I would like to save all transition matrices in order to perform operations on them (average, sum, weight...)

採用された回答

Voss
Voss 2024 年 1 月 31 日
transMatRD = cell(5); % 5x5 cell array
for i=1:25
transMatRD{i} = transprob(...)
end
  2 件のコメント
Aleksandar
Aleksandar 2024 年 2 月 1 日
Thank you, that's it!
Voss
Voss 2024 年 2 月 1 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by