Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Creating a matrix from an original matrix of 2464*2464
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to use following code:
CV = [56:56:2464]
for i = 1:44
if i==1
j=1
elseif i>1
j=CV(i-1)+1
end
TCI(i)=sum(sum(M(:,j:CV(i))))
for ii = 1:LengthIO
for jj = j: CV(i)
if jj< CV(i)
ImportsCoefficientMatrix(ii,jj) = ImportsBreakdown(ii,jj)/TCI(i);
end
end
end
end
But it keeps on running forever.
All I want to do is create a new matrix which has same dimensions as M(2464*2464) but every element of it in first 56 columns then it is divided by sum of first 56 columns. If is in next 56 columns it is divided by next 56 columns and so on..
Can someone help??
Thanks
댓글 수: 2
Roger Stafford
2017년 11월 16일
To fully understand your code we need to know what the CV values and the LengthIO scalar are equal to. Your figures of 44 and 56 (44*56=2464) don't match your figure of 2000 for the total number of columns. Also I see no reason why the code should run "forever"; it looks as if it should involve something in the neighborhood of four million steps which ought not to take very long. If each of your groups of columns has the same number of columns in it, namely 56, the use of CV here seems very awkward. Please give us some more accurate information.
답변 (1개)
the cyclist
2017년 11월 16일
편집: the cyclist
2017년 11월 17일
Does this do what you want?
% Size of one dimension of your matrix
N = 44*56;
% Define some pretend data (You don't need this step)
rng default
M = rand(N,N);
% Transform array into slices of 56 columns
Mr = reshape(M,N,56,[]);
% Perform the division
Mr_sum = sum(sum(Mr,1),2);
Mr_normalized = Mr ./ Mr_sum;
% Transform back
M_normalized = reshape(Mr_normalized,N,N);
It wasn't clear to me if you wanted to divide by the grand sum of all the elements in the first 56 columns, or divide each column individually.
댓글 수: 5
the cyclist
2017년 11월 17일
OK. My code should do exactly what you want, without using for loops, so it should be fast.
I added some comments.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!