필터 지우기
필터 지우기

How do i set class members by calling its own methods?

조회 수: 2 (최근 30일)
Zain Ahmed
Zain Ahmed 2022년 10월 9일
답변: Steven Lord 2022년 10월 9일
I wanted to create a class where i can implement a class and set its members by calling its own methods.
This is the example class here:
classdef MANOVA1
%MANOVA1 calculate manova1
% This class perform ANOVA1 on dataset
properties (GetAccess = public)
g;
end
properties (Access = private)
data;
end
properties (Dependent)
Test_statistics;
p_value;
end
methods
function obj = MANOVA1(filename)
if nargin == 1
obj.setData(filename);
end
if isempty(obj.g)
obj.setg();
end
end
function setData(obj, filename)
obj.data = struct2cell(load(filename));
end
function setg(obj, data)
if (nargin == 1)
data = obj.data;
end
obj.g = length(data);
end
end
end
I was trying to call the class to the dataset: problem_5_1 exercise, by this following code:
obs = MANOVA('dataset_problem_5_1.mat')
disp(obs.g)
But when i run this code, the values are empty, because the members inside the class wouln't set when calling from class' own methods. I could do that with C++ and Python.

답변 (1개)

Steven Lord
Steven Lord 2022년 10월 9일
By default, classes in MATLAB are value classes. See this documentation page for a discussion of the differences between value classes and handle classes. Also see this documentation page for a discussion of how classes in MATLAB behave differently from classes in other object-oriented languages.

카테고리

Help CenterFile Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by