필터 지우기
필터 지우기

Fastest way to create matrix of interactions many times

조회 수: 2 (최근 30일)
CJ
CJ 2018년 3월 28일
편집: CJ 2018년 3월 28일
I have this code, where I have 8 columns in my matrix of regressors X (36 unique interactions):
interactions=zeros(size(X,1),36);
iii=0;
for kk=1:8
for jj=kk:8
iii=iii+1;
interactions(:,iii)=X(:,kk).*X(:,jj);
end
end
X_all=[ones(size(X,1),1),X,interactions];
I have to run this 500,000 times for different Xs.
The code above is much faster when doing it many times than running the matlab function below many times (due to overhead I think):
X_all=x2fx(X,'quadratic');
Is there some way to make my code faster? Perhaps avoid the loop somehow?
The profiler shows that most of the time is spent on the multiplication part, followed by the last line.

답변 (0개)

카테고리

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