Conversion from an old to a new version of a class with different property names
34 ビュー (過去 30 日間)
古いコメントを表示
Let's say that I have a custom class testClass
classdef testClass
properties
input1
computationResultPropertyNameThatsTooLong
end
methods
function tc = testClass(input1)
tc.input1 = input1;
expensiveFunction = @sqrt;
tc.computationResultPropertyNameThatsTooLong = expensiveFunction(input1);
end
end
end
I'm offloading the computation of the testClass objects (of which I have tens of thousands) to another machine. Is there any way to make it so that I can alter the property names of testClass in a "clean " way (let's say I change computationResultPropertyNameThatsTooLong to computationResultBetterName) such that I can load in the data from the *.mat file as valid testClass objects? I can of course run the computations again, but I would prefer not to.
0 件のコメント
採用された回答
Matt J
2025 年 8 月 26 日 20:08
編集済み: Matt J
2025 年 8 月 26 日 20:11
One way is with a Dependent property. This makes it so you can reference the same property using tc.shortname.
classdef testClass
properties
input1
end
properties (Dependent)
shortname
end
properties (SetAccess = immutable, Hidden)
computationResultPropertyNameThatsTooLong
end
methods
function tc = testClass(input1)
tc.input1 = input1;
tc.computationResultPropertyNameThatsTooLong = expensiveFunction(input1);
end
function val=get.shortname(tc)
val=tc.computationResultPropertyNameThatsTooLong;
end
end
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Class Introspection and Metadata についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!