Class Property assignment and read
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Handle Classes 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!