How to build ratio between two columns of a matrix?

I have a matrix of size 102 x 2555 I want to select each column from 1 to 2555 of this matrix and then divide to each column of this matrix. For example: I have matrix
A=
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 4 6
5 6 8 7 1 3
I want to build the ratios like this:
ratio1=column1./each column in matrix A
ratio2=column2./each column in matrix A
ratio3=column3./each column in matrix A
....
ratio6=column6./each column in matrix A
Thanks for your help!

 채택된 답변

the cyclist
the cyclist 2013년 9월 10일

1 개 추천

A= ...
[1 2 3 4 5 6; ...
2 3 4 5 6 7; ...
3 4 5 6 4 6; ...
5 6 8 7 1 3];
[nrow,ncol] = size(A);
for n = 1:ncol
ratio{n} = bsxfun(@rdivide,A(:,n),A)
end

댓글 수: 4

Viet Duc
Viet Duc 2013년 9월 10일
편집: Viet Duc 2013년 9월 10일
Thanks for your help!
But it's out of memory
Size of my matrix is 2555 columns and 102 rows :(
Hm. I can run this code with no problem.
A = rand(102,2555);
[nrow,ncol] = size(A);
ratio = cell(2555,1);
for n = 1:ncol
ratio{n} = bsxfun(@rdivide,A(:,n),A);
end
Jan
Jan 2013년 9월 10일
편집: Jan 2013년 9월 10일
@Viet Duc: As result you get 2555 matrices of type double with 102*2555 elements, which occupy about 5.32 GB. With a 16 GB machine and a 64 bit system, this is no problem, but it fails for a 32 bit machine.
Do you really need such a large pile of data simultaneously in the memory?
num2cell(bsxfun(@rdivide,permute(A,[1 3 2]),A),[1 2])

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

추가 답변 (1개)

Viet Duc
Viet Duc 2013년 9월 11일

0 개 추천

Thank you all.
Maybe, I should check my matrix and remove some columns and rows

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2013년 9월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by