Why is the built-in quantizer object in MATLAB 6.5 (R13) passed by reference and not by value?
2 views (last 30 days)
Show older comments
The following code demonstrates how the quantizer object is passed by reference.
function BugDemo()
q = quantizer
Change(q)
q
function Change(Q)
Q.format = [1 0]
The results of this code shows that changes made to the quantizer object in the "Change" function alter it within the "BugDemo" function.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
Although this is different behavior than that in previous versions, it is the expected behavior.
The following steps will simulate the R12 behavior within R13:
1. Create a copy of the object within 'BugDemo' before passing it:
function BugDemo()
q = quantizer
q2 = copyobj(q);
Change(q2)
q
function Change(Q)
Q.format = [1 0]
2. Create a copy of the object within 'Change' before altering it:
function BugDemo()
q = quantizer
Change(q)
q
function Change(Q)
Q2 = copyobj(Q);
Q2.format = [1 0]
0 Comments
More Answers (0)
See Also
Categories
Find more on Cast and Quantize Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!