Class Property assignment and read
Mostrar comentarios más antiguos
if true
% code
endI am trying to use classes in MATLAB and I’m tripping over a property assignment in a class. I am trying to assign a value to a property in one function and read this property back in another function.
When I go to read the value back the value I assigned it no longer is applied to the property. I am not sure what I am doing wrong? Test class
classdef Class_Test
%-------------------------------
% Properties
%-------------------------------
properties (Access = private)
X
end
%-------------------------------
% Methods
%-------------------------------
methods
function set_X(this)
this.X = 1;
this.X
end
function read_X(this)
this.X
end
end
end
Output of Object:
>> TC = Class_Test;
>> TC.set_X
ans =
1
>> TC.read_X
ans =
[]
What I expected was:
>> TC.read_X
ans =
1
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Handle Classes en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!