Class method is 'call by value' function, isn't it?
Mostrar comentarios más antiguos
classdef myClass
properties
prop1
end
methods
function this_ = myClass(argin1_, argin2_) % constructor
this_.prop1 = argin1_ + argin2_;
end
function setter1(argin)
prop1_ = argin + 1;
end
function this_ = setter2(this_, argin)
this_.prop1 = argin + 1;
end
end
end
Matlab editor give me a error message for setter1 method.
It tells me that first input arg must be instance itself, and must be returned after manipulation.
This implies a class method of Matlab is a cal-by-value function.
I have very large fixed size array data as a property of my class,
and want to update a couple of elements in it many times very quickly.
so, definitely I want to avoid 'call by value' function as my method.
What would be a option for me,
Thank you.
Respuesta aceptada
Más respuestas (1)
per isakson
el 20 de En. de 2022
0 votos
"It tells me that first input arg must be instance itself" Yes, Matlab requires that the instance is passed explicitly as in setter2. That applies to both handle and value classes.
"What would be a option for me" Use a handle class.
Categorías
Más información sobre Class File Organization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!