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!