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

2 vues (au cours des 30 derniers jours)
Yakir Nisim
Yakir Nisim le 6 Jan 2021
Commenté : James Tursa le 19 Jan 2021
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 commentaires
Walter Roberson
Walter Roberson le 6 Jan 2021
R2020b? or an earlier version?
Yakir Nisim
Yakir Nisim le 6 Jan 2021
it's R2020b

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 12 Jan 2021
Modifié(e) : James Tursa le 12 Jan 2021
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.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 7 Jan 2021
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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by