Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Creating a matrix from an original matrix of 2464*2464
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Roger Stafford
le 16 Nov 2017
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.
Réponses (1)
the cyclist
le 16 Nov 2017
Modifié(e) : the cyclist
le 17 Nov 2017
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 commentaires
the cyclist
le 17 Nov 2017
OK. My code should do exactly what you want, without using for loops, so it should be fast.
I added some comments.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!