How can I choose a model depending on the highest value of coefficient of determination in Matlab?

I have a cell array which has many models and a double array which has the values of their coefficient of determination. I can specify the highest value of the coefficient. However, how can I choose the corresponding model for the highest value automatically?
Best regards& many thanks in advance

 採用された回答

Hi Nasir,
Assuming that you have a cell array 'cModels' and a double array 'rSquare' containing the coefficients of determination for the corresponding models in 'cModels', you can use 'find' function as explained below:
function [model] = returnModel(cModels, rSquare)
ind = find(max(rSquare)==rSquare); % This finds the index of the highest/max value
% of the coefficient of determination
model = cModels(ind); % returns the model corresponding to the maximum coefficient
end
If this is not what you are looking for, please post some more information about your data or an example of what is the desired output.
-Nalini

3 件のコメント

ND
ND 2015 年 5 月 20 日
Thank you very much for your comment. I have tried this code, but it gives me an error message: Function definitions are not permitted in this context.
Can you provide more information about how you are using the function and the complete error message?
ND
ND 2015 年 5 月 28 日
Dear Nalini, Please, above is the whole error message and I used this code as it is once and I tried to save the function at another trial but it is failed? Many thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

ND
2015 年 5 月 18 日

コメント済み:

ND
2015 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by