「読み取り専用であるため、クラス 'dtmc' の 'P' プロパティを設定でき​ません。」を解決する​にはどうすればよいで​すか?

マルコフ連鎖のMATLAB関数について質問です。
https://jp.mathworks.com/help/econ/dtmc.html
「読み取り専用であるため、クラス 'dtmc' の 'P' プロパティを設定できません。」のエラーを回避し、
mc = dtmc(P)を実行後のmc.Pを編集可能にしたいのですが、どうすればよいでしょうか?

1 Comment

mc.Pを編集する為にdtmc関数を使って新たにmcを作り直せば良いと思ったのですが、直接mc.Pを変更したい理由があるのでしょうか?
mc = dtmc([0.5 0.5 0 0; 0.5 0 0.5 0; 0 0 0 1; 0 0 1 0], ...
'StateNames',["Depression" "Recession" "Stagnant" "Boom"])
mc =
dtmc with properties: P: [4×4 double] StateNames: ["Depression" "Recession" "Stagnant" "Boom"] NumStates: 4
mc.P
ans = 4×4
0.5000 0.5000 0 0 0.5000 0 0.5000 0 0 0 0 1.0000 0 0 1.0000 0
mc.P = [0.5 0.5 0 0; 0.5 0 0.5 0; 0 0 0 1; 0 0 1 0]
Unable to set the 'P' property of class ''dtmc'' because it is read-only.

Sign in to comment.

 Accepted Answer

Atsushi Ueno
Atsushi Ueno on 15 Jan 2022
which dtmc % 御使用の環境により場所は異なります
/MATLAB/toolbox/econ/econ/@dtmc/dtmc.m % dtmc constructor
の最初の方にある
properties (SetAccess = private, GetAccess = public) % privateをpublicに変更する
P % Normalized transition matrix
end
上記のprivateをpublicに変更すればやりたい事が実現するはずです。(動作確認していません)
ただToolboxの中身を変更する事はあまり推奨できないので、独自の構造体を作成する方が良いと思います。

1 Comment

Yusuke Kurisu
Yusuke Kurisu on 15 Jan 2022
先程コメントをいただいた件につきましては、複数の解析対象を複数回dtmc関数を実行し、それぞれの遷移確率の平均をmc.Pに代入し、プロットしてみたかったためです。
また、いただいた回答により、やりたい事が実現できました(あまり多用しないようにします)。
大変ありがとうございました。

Sign in to comment.

More Answers (0)

Categories

Find more on Physics 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!