.Selecting the data series for next loop

3 ビュー (過去 30 日間)
Prakhar Modi
Prakhar Modi 2019 年 8 月 6 日
コメント済み: Prakhar Modi 2019 年 8 月 9 日
Hello Everyone,
I have 1 main series lets say it as y and 5 sub series lets say it as x1.
Now I am calculating z1 using the equation z1= y-x1.
and then I am calculating the coefficient of determination that is R^2. Now what I want is that as from 5 x1 I will get 5 z1 series which will give me 5 R^2, so now I want that code should select the x1 series which gives maximum value of R^2 and assign it as x1 series for further computation.
After this, of the remaining 4 x1 series, which will be taken as x2 series, i again want to calculate z2 using the equation z2=y-x1-x2. Here x1 and y are fixed where as x2 is changing. I have done this in excel but I have lot of series. I just want to know how to direct the code to select the series of maximum R^2.
Thanks in advance

採用された回答

Bob Thompson
Bob Thompson 2019 年 8 月 6 日
Is y a single value?
I'm not entirely sure I know what you're asking for, but maybe something like this can work?
y = randi(100,1,1);
x = randi(50,5,1);
c = 1;
xc = [];
while length(x)>1
z = y-sum(xc)-x; % Calculate z values for all x
xc(c) = x(z==max(z)); % Record x which results in max z ( I know you want max R^2 but you didn't give a relationship for z and R^2)
x = x(x~=xc(c)); % Remove recorded x value from x
c = c + 1;
end
xc(c) = x; % Record last value of x
  2 件のコメント
Prakhar Modi
Prakhar Modi 2019 年 8 月 7 日
ok thanks I will try this.
Prakhar Modi
Prakhar Modi 2019 年 8 月 9 日
Hello Bob,
whatever you suggested was correct but now I am stuck with something else. The thing is I got the way to remove x because it is present in equation of z, but in my code as x is 15x1 matrix and similarly y is 15x1 matrix and while calculating z I am not directly using x in the equation. let say I am computing p from x than q and than q is used to calculate z. But ultimately I have to remove the x which 15x1 matrix for further computation. So do you have any more suggestions.
Thanks in advance

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by