インスタンスメソッドの第2出力をcellfunで取得する方法
2 views (last 30 days)
Show older comments
Shojiro SHIBAYAMA
on 17 Jun 2020
Commented: Shojiro SHIBAYAMA
on 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出力だけを出力するインスタンスメソッドを定義する
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!