Adding an Extra Input Parameter to the Function

5 ビュー (過去 30 日間)
MByk
MByk 2018 年 5 月 25 日
コメント済み: MByk 2018 年 5 月 25 日
How can I add an extra input parameter to the function below? I want to add switch-case inside the function.
[features,history] = sequentialfs(@fun,X,Y,...
'direction','forward','cv',cvt,'options',dsp_options);
function cl_err = fun(xTrain,yTrain,xTest,yTest)
.....
end
  2 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 5 月 25 日
What does switch case have to do with the input arguments? Please clarify your question.
MByk
MByk 2018 年 5 月 25 日
編集済み: MByk 2018 年 5 月 25 日
Actually I asked this question before I want to compare different classifiers. So I planned to pass an input parameter to the function to select different classifier in each iteration. Like below. Btw all suggestions are welcomed.
function cl_err = fun(xTrain,yTrain,xTest,yTest,i)
switch i
case 1
.....
case 2
....
end
end

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

採用された回答

dpb
dpb 2018 年 5 月 25 日
Since sequentialfs is a builtin Toolbox function, you'll really not want to mess with it directly; write a wrapper function around it to use with a specific alternate name and make the modifications desired there; then have it pass the arguments on to the builtin function.
  1 件のコメント
MByk
MByk 2018 年 5 月 25 日
Thank you very much.

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

その他の回答 (1 件)

Guillaume
Guillaume 2018 年 5 月 25 日
[features,history] = sequentialfs(@(xTrain,yTrain,xTest,yTest) fun(xTrain,yTrain,xTest,classifier) , ...
X,Y,'direction','forward','cv',cvt,'options',dsp_options);
function cl_err = fun(xTrain,yTrain,xTest,yTest,i)
switch i
...
Basically, create an intermediate anonymous function
@(xTrain,yTrain,xTest,yTest) fun(xTrain,yTrain,xTest,classifier)
which calls fun with the extra argument classifier (which will become i in fun).
  1 件のコメント
MByk
MByk 2018 年 5 月 25 日
Thank you very much.

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

カテゴリ

Help Center および File ExchangeConstruction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by