when does changing variable's value affects its structure address?

1 回表示 (過去 30 日間)
Yakir Nisim
Yakir Nisim 2021 年 1 月 6 日
コメント済み: James Tursa 2021 年 1 月 19 日
Hey,
I was wondering why somtimes MatLab will change variable's structure address when the value of the variable is changed while in other time the address will remain the same. I am attaching 2 example cases below.
Thank you!
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 6 日
R2020b? or an earlier version?
Yakir Nisim
Yakir Nisim 2021 年 1 月 6 日
it's R2020b

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

採用された回答

James Tursa
James Tursa 2021 年 1 月 12 日
編集済み: James Tursa 2021 年 1 月 12 日
In addition to what Walter has written, I would point out that all of the rules for variable creation, assignment, and sharing have never been published. And these rules have undergone many changes over the years. You can often uncover what has happened with a particular line in a particular MATLAB version using format debug and/or a mex routine to give you some insight into the rules, but that's the best you can do. From a practical standpoint, you will never be able to discover all of these rules even for a particular version of MATLAB. And whatever you discover for one MATLAB version might not apply to a different version of MATLAB.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 1 月 7 日
When you do a literal initialization, a hidden copy of the value is taken for re-use if you reinitialize in exactly the same way. The hidden copy is a shared version, so the very first time you write to the variable, MATLAB needs to unshare the variable, which changes its address.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by