インスタンスメソッドの第2出力をcellfunで取得する方法
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Shojiro SHIBAYAMA
am 17 Jun. 2020
Kommentiert: Shojiro SHIBAYAMA
am 17 Jun. 2020
あるクラス SomeClass のインスタンスメソッドが2つ変数を返すときに、cellに SomeClass のインスタンスを初期化して保存しておいて、cellfunでまとめて実行する方法はありますか?
以下のようなコードを書いています。
X; % some data
objs(:) = {SomeClass()}; % initialize
[~, ret] = objs{1}.predict(X); % predict
% bulk execution
cellfun(@(x)x.predict(X), objs)
例えば load 関数では、出力を構造体で渡すことができるので次のように書くことができます。第2引数の取得とは異なりますが、以下のような挙動を、第2引数でも実行したいです。
filepaths = {'path1', 'path2', 'path3', ...};% file paths
data = cellfun(@(f) {load(f)}, filepaths);
data{1} %=> returns a structure having all variables in `path1` file.
うまく説明できていないかもしれませんがよろしくおねがいします。
解決策(案、あまりやりたくない):
第2出力だけを出力するインスタンスメソッドを定義する
2 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB でのオブジェクト指向デザイン finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!