Instantiate関数がThatの「空白」インスタンスを作成しないのはなぜですか?
私は次の最小限のクラスを持っています:
classdef That < handle
properties
This = ''
end
methods
function Self = That(String)
if exist('String','var') == 1
Self.This = String;
end
end
function Self = Instantiate(Self)
if isempty(Self)
Self(1,1) = That;
end
end
end
end
私が走ったら
This = That;
disp(size(This)) % 1x1
disp(isempty(This)) % False
そしてそれはすべて良いです、私はクラスの「空白」インスタンスを持っています
私が走ったら
TheOther = That.empty;
disp(size(TheOther)) % 0x0
disp(isempty(TheOther)) % True
TheOther.Instantiate;
disp(size(TheOther)) % 0x0 - Expecting 1x1
disp(isempty(TheOther)) % True - Expecting False
ご覧のとおり、Instantiateの実行が機能せず、理由がわかりません。確かに、空のインスタンスを空ではないが空白のインスタンスに置き換える必要がありますか?
アップデート :
SCFrenchからのリンクは、「空の配列の作成」という見出しの下にあるこのhttp://www.mathworks.com/help/techdoc/matlab_oop/brd4btr.htmlにつながりますが、これも機能しませんでした。
function Self = Instantiate(Self)
if isempty(Self)
Blank = That;
Props = properties(Blank)
for idp = 1:length(Props)
Self(1,1).(Props{idp}) = Blank.(Props{idp});
end
end
end