Hello People :),
I have a 2464x220 matrix with 44 countries represented by 56 rows each and 5 columns each. I want to do some matrix mulitplication and sum the co2 emissions e11 +e21 in the end, but it calculates 44 times the same number(which is correct, but just for 1 country ) . It just gives me the first countries number and repeats it although i am trying to tell matlab to calcluate it for 44 different countries. I did the following:
kk=1:56:2464;
yy=1:5:220;
Co2_CB=ones([44,1]);
for j=kk
v=j+55;
r=yy;
q=r+4;
e11_j=sum(Q(j:v,r:q),'all');
e21_j=Q(1:2464,r:q);
e21_j(j:v,:)=[];
e21_j=sum(e21_j,'all');
Co2_CB(j)=e11_j+e21_j;
end
Co2_CB(Co2_CB==0)=[];
Co2_CB(Co2_CB==1)=[];
I dont understandt why matlab does not calculates the other 43 numbers.
Thanks in advance

6 comentarios

Walter Roberson
Walter Roberson el 12 de Feb. de 2021
Your kk is not sequential so your for j=kk is not using sequential numbers, so your C02_CB(j) is not going to write to sequential locations.
Matt J
Matt J el 12 de Feb. de 2021
Editada: Matt J el 12 de Feb. de 2021
It is not clear from your code what e11 and e21 are really supposed to represent. These lines,
e11_j=sum(Q(j:v,r:q),'all');
e21_j=Q(1:2464,r:q);
e21_j(j:v,:)=[];
e21_j=sum(e21_j,'all');
Co2_CB(j)=e11_j+e21_j;
are equivalent to the single line of code
Co2_CB(j)=sum(Q(:,r:q),'all')
So, the partitioning into e11 and e21 is inconsequential in what you have posted for us thus far.
Victoria Pake
Victoria Pake el 12 de Feb. de 2021
I have a big matrix 2464x220 representing emission of 56 sectors of 44 countries ( on the rows 56x44=2464), the columns represent final demand of the 5 different consumers of 44 countries(5x44=220). I want to compute 2 different emission calculations, since it the e21 represent emissions outside of the country imported, I need for each country the all emission of the countrys specifiy columns but always avoiding the domestic 56 sectors (rows).
e11 just represent the countrys domestic emission,1: 56 domestic sectors and 1:5 domestic demand
Matt J
Matt J el 12 de Feb. de 2021
Editada: Matt J el 12 de Feb. de 2021
But if e11_j is the total emission from the j-th country and e21_j is the total emission from every other country, then the sum e11_j+e21_j will simply be the total emission from all countries. There is no real j-dependence in e11_j+e21_j .
Victoria Pake
Victoria Pake el 12 de Feb. de 2021
it worked now, it was somethin with the sequence
Victoria Pake
Victoria Pake el 12 de Feb. de 2021
thanks all of you

Iniciar sesión para comentar.

 Respuesta aceptada

Matt J
Matt J el 12 de Feb. de 2021
Editada: Matt J el 12 de Feb. de 2021

0 votos

Note that you can use sepblockfun
to do blockwise summation over the 56x5 sub-tiles of Q.
E11=sepblockfun(Q,[56,5],'sum')
This might make it easier to see how to get the restof what you want.

1 comentario

Victoria Pake
Victoria Pake el 12 de Feb. de 2021
Hey Matt,
Thanks for your anwser, but i think the main problem is the e21, because i did a different method and it worked:
tt=1:56:2464;
pp=1:5:220;
Co2_PB=ones([44,1]);
for i=tt;
o=i+55;
p=pp;
q=p+4;
e11_j=sum(Q(i:o,p:q),'all');
e12_i=sum(Q(i:o,1:220));
e12_i(:,p:q)=[];
e12=sum(e12_i,'all');
Co2_PB(i)=sum(e11_j+e12,'all');
end
Co2_PB(Co2_PB==0)=[];
Co2_PB(Co2_PB==1)=[];
since the e11 is the same under both methods, i dont get what the problem is.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Feb. de 2021

Comentada:

el 12 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by