can i used cellfun with a function which has more than one input?

64 ビュー (過去 30 日間)
Charles
Charles 2017 年 10 月 8 日
コメント済み: Cedric 2017 年 10 月 8 日
Hello I have a function as follows
[ chart_datavortex ] = chart_funcv( 'AUD_USD', New_dataopenbidx, New_datahighbidx, New_datalowbidx,New_datax, New_datavol )
The function takes 6 inputs, however i wish to use CELLFUN so as to input an array of the first input. Thus I want to do something like the following
C = {'GBP_USD', 'GBP_AUD', 'USD_CAD'}
A = cellfun(chart_funcv,C)
This fails with error
Not enough input arguments.
Please advise

採用された回答

Cedric
Cedric 2017 年 10 月 8 日
編集済み: Cedric 2017 年 10 月 8 日
Yes, use an anonymous function (or define a function inline => name your anonymous function) to wrap the call to chart_funcv, and pass the wrapper to CELLFUN:
C = {'GBP_USD', 'GBP_AUD', 'USD_CAD'} ;
wrapper = @(x) chart_funcv( x, New_dataopenbidx, New_datahighbidx, New_datalowbidx,New_datax, New_datavol ) ;
A = cellfun( wrapper, C ) ;
If the output of the function is not scalar, set 'UniformOutput' to false in the call to CELLFUN:
A = cellfun( wrapper, C, 'UniformOutput', false ) ;
and A will be a cell array of (non-scalar) outputs.
  7 件のコメント
Charles
Charles 2017 年 10 月 8 日
Yes. Correct the function returns a cell array. Thank you for this. Much appreciated. I will try it
Cedric
Cedric 2017 年 10 月 8 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by