필터 지우기
필터 지우기

Matrix operations without for structure

조회 수: 1 (최근 30일)
Pedro
Pedro 2012년 4월 21일
I'm making a program in Matlab and now I am trying to make it run faster.
In one step I need to make operations in a matrix with more than 60000 rows and 2 columns. Now, I have a for structure to go to every line and make the following operation: (line-mean)*s*(line-mean)'
line is the line that is selected in each iteration, mean, is the result of the mean of each column, and s is a matrix 2x2.
I would like to know if it's possible to make this operation without a for structure, so that the program runs faster.
Thanks for your atention

답변 (2개)

Rick Rosson
Rick Rosson 2012년 4월 21일
Please try:
M = 60e3;
N = 2;
A = rand(M,N);
s = rand(N,N);
mu = ones(M,1)*mean(A);
X = A - mu;
R = X*s*X';
HTH.
  댓글 수: 1
Pedro
Pedro 2012년 4월 21일
When I try to do that, it gives me the error: "Out of memory."
I think your solution only works with smaller matrices, or my computer can't make operations with big matrices like this one.

댓글을 달려면 로그인하십시오.


Teja Muppirala
Teja Muppirala 2012년 4월 22일
M = 60e3;
N = 2;
A = rand(M,N);
s = rand(N,N);
Am = bsxfun(@minus,A,mean(A)); %subtract the column means
V = sum((Am*s).*Am,2); % Do the matrix operation

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by