Several regress() without looping.

조회 수: 2 (최근 30일)
Rodolphe
Rodolphe 2016년 3월 23일
편집: John D'Errico 2016년 3월 23일
Basically, im doing regress(X,Y) on several different X, while Y remain unchanged. So far, im looping on each X but I have thousands so it's taking forever. Any ideas on how to avoid the loop? Thanks!

답변 (1개)

John D'Errico
John D'Errico 2016년 3월 23일
편집: John D'Errico 2016년 3월 23일
While it is possible to do so for a fixed X, with changing Y where you would see a speed gain, the opposite is not possible.
Yes, there are some tricks where you can create sparse block diagonal matrices, but you would not gain too much over a simple loop, and you would no longer have access to the many pieces of information that regress returns beyond the basic regression coefficients. That you could get as easily from a loop around use of the backslash operator applied to your sequence of problems.
The point is, much of the time required for regress lies in the computation of those extra stars, R^2, p values for the parameters, etc. Skip them, and all you need to do is use backslash. It will be faster, but then you don't get that information.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by