Error when using get method (MATLAB:class:DependentGet)
4 ビュー (過去 30 日間)
古いコメントを表示
Consider the following Class and the short script to build the blocks of a table. The idea behind the script is that T stands for the whole table where as U and V are two subblocks, constituting the table. Why does Matlab throw this error when I query V.top?
In class 'TestComponent', the get method for Dependent property 'top' attempts to access the stored property value. Dependent properties don't store a value and can't be accessed from their get method.
Script:
T = TestComponent
U = TestComponent
V = TestComponent
T.add(U)
T.add(V)
V.top
Class:
classdef TestComponent < handle
properties
Children
previousPeer
topRoot = 1
height = 1
end
properties (Dependent)
top
end
methods
function val = get.top(obj)
if ~isempty(obj.previousPeer)
val = obj.previousPeer.top + obj.previousPeer.height;
else
val = obj.topRoot;
end
end
function add(obj,child)
if isempty(obj.Children)
obj.Children{1} = child;
else
child.previousPeer = obj.Children{end};
obj.Children{end + 1,1} = child;
end
end
end
end
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!