Problem in using function handle?

1 回表示 (過去 30 日間)
Abhinav
Abhinav 2015 年 8 月 20 日
コメント済み: Abhinav 2015 年 8 月 20 日
I have written a function 'PLSR_A', which works fine. The function is as follows
[beta,yfit,q,RMSE] = PLSR_A(X,Y,npc)
I want to create a function handle in matlab 'crossval' function which will compute the cross-validation error for leave one out. Therefore, I defined a function handle as follows
fun = @(xT,yT,xt,yt) ((yt-(([1 xt])*PLSR_A(xT,yT,npc)))^2);
But when I compute fun with different 'npc' values it gives same output, however, using the function PLSR_A directly, gives different outputs for different 'npc' (which is correct).
I have read the documentation for function handle but couldn't find the problem, can anyone help?

採用された回答

Adam
Adam 2015 年 8 月 20 日
編集済み: Adam 2015 年 8 月 20 日
npc is a fixed input to that function handle, it will be set at the time the function handle is created as a constant. If you want it to be one of your input variables you need:
fun = @(xT,yT,xt,yt,npc) ((yt-(([1 xt])*PLSR_A(xT,yT,npc)))^2);
  1 件のコメント
Abhinav
Abhinav 2015 年 8 月 20 日
Thanks a lot Adam!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by