Problem with a rolling regression programme please help

2 ビュー (過去 30 日間)
Andrew Wileman
Andrew Wileman 2015 年 1 月 8 日
コメント済み: Star Strider 2015 年 1 月 8 日
Hi,
I'm new to Matlab and was wondering if anyone may be able to help with a program I'm writing as I have seem to have hit a stumbling block. I'm trying to write a program that will will move along a data set using a window, at each increment, the program calls the function exp1fit, which calculates the regression coefficients for the exponential A and B within the window. Therefore a exponential function that fits the data in the window will be produced. The problem is getting the moving window to work (this is adapted from wreg code by Léon Bueckins), it keeps coming up with a 'Index exceeds matrix dimensions' warning and I can't seem to resolve it. I was wondering please, if anyone had any ideas.
Thanks, Andy
  2 件のコメント
Star Strider
Star Strider 2015 年 1 月 8 日
Please attach your .m file, and post the line throwing the error.
Andrew Wileman
Andrew Wileman 2015 年 1 月 8 日
The problem seems to lie with ,: in the code
[A(:,i),B(:,i)] = exp1fit(x(s:s+window_length-1,:),y(s:s+window_length-1,:));
if this is removed it works, however it is not calculating the regression just in the window, but the whole function.

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

採用された回答

Star Strider
Star Strider 2015 年 1 月 8 日
One way to deal with that sort of problem is to use the minimum of s+window_length-1 and length(x).
Change the references to:
x(s:min(s+window_length-1, length(x)),:),y(s:min(s+window_length-1, length(y)),:)
and see if that makes a difference. (I didn’t test this specifically, but I’ve used it successfully in the past.) The idea is that it will use the shortest of the two options, so if all goes well, you will not read beyond the ends of your variable vectors. You can make that a bit more efficient by creating a separate index range:
idxrng = s:min(s+window_length-1, length(x));
and then just referring to it in your ‘x’ and ‘y’ subscripts. It looks like the author was attempting to do that by calculating ‘stoppingpoint’, but for some reason, it’s not working as it should.
  2 件のコメント
Andrew Wileman
Andrew Wileman 2015 年 1 月 8 日
Thanks for your help, it works now :)
Star Strider
Star Strider 2015 年 1 月 8 日
My pleasure!

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

その他の回答 (1 件)

Andrew Wileman
Andrew Wileman 2015 年 1 月 8 日
Thanks for getting back to me.
The problem seems to be with lines 66 & 77 in the window_regression mfile.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by