when does changing variable's value affects its structure address?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
James Tursa
2021년 1월 19일
See also this related thread for a bug in FORMAT DEBUG for scalars in R2019b and later:
추가 답변 (1개)
Walter Roberson
2021년 1월 7일
I think you might be running into https://www.mathworks.com/matlabcentral/answers/383188-mex-inplace-change-problems-r2015b-and-later?s_tid=srchtitle
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 Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!