Error when using get method (MATLAB:cl​ass:Depend​entGet)

6 visualizaciones (últimos 30 días)
Jan-Andrea Bard
Jan-Andrea Bard el 20 de Mayo de 2020
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

Respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by