Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Creating a matrix from an original matrix of 2464*2464
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Roger Stafford
el 16 de Nov. de 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.
Respuestas (1)
the cyclist
el 16 de Nov. de 2017
Editada: the cyclist
el 17 de Nov. de 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 comentarios
the cyclist
el 17 de Nov. de 2017
OK. My code should do exactly what you want, without using for loops, so it should be fast.
I added some comments.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!