2015-06-10 3 views
0

Возможно ли получить свойства из другого класса в MatLab?Получить свойства из другого класса (matlab)

У меня есть два класса: ProjectTable и AllProjectTables.
В ProjectTable я попытался со следующим:

properties (GetAccess = ?AllProjectTables) 

Но это не работает.

+0

Можете ли вы дать более подробную информацию о том, что не работает? См. Ответ ниже для рабочего примера. – zeeMonkeez

ответ

0

Вот рабочий пример:

classdef ProjectTable 
    properties (GetAccess = ?AllProjectTables) 
     Value 
    end 
    methods 
     function obj = ProjectTable(val) 
      obj.Value = val; 
     end 
     function r = addTwo(obj) 
      r = obj.Value + 2; 
     end 
    end 
end 

classdef AllProjectTables 
    properties 
     Project_Table 
    end 
    methods 
     function obj = AllProjectTables(project_table) 
      obj.Project_Table = project_table; 
     end 
     function r = test(obj) 
      r = obj.Project_Table.Value; 
     end 
    end 
end 

И тест:

>> a=ProjectTable(45) 

    a = 

    ProjectTable with no properties. 

    >> a.Value 
    You cannot get the 'Value' property of ProjectTable. 

    >> b=AllProjectTables(a) 

    b = 

    AllProjectTables with properties: 

     Project_Table: [1x1 ProjectTable] 

    >> b.test 

    ans = 

     45 

    >> b.Project_Table.Value 
    You cannot get the 'Value' property of ProjectTable. 

    >> 
Смежные вопросы