Class Property assignment and read
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Handle Classes 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!