the problem is that the length of Ei will differ for the values of Eg. To solve this with for loop i preallocate 'aa' with NaN everywhere
Eg=.5:.05:1.3;
aa=zeros(17,26)+NaN;
for ig=1:length(Eg);
Ei=0:0.05:Eg(ig)-0.05;
for ii=1:length(Ei);
aa(ig,ii)= quad( @(E)(E.^2) ./ (exp(E./0.5172)-1), Ei(ii) , Eg(ig));
end
end
clear ig ii
without the for loop: i create a 'meshgrid' and then i cut of every value for Ei: if EI>=EG then i set EI=EG-0.05
Eg=.5:.05:1.3;
Ei=0:0.05:Eg(end)-0.05;
[EI,EG]=meshgrid(Ei,Eg);
EI(EI>=EG)=EG(EI>=EG)-0.05;
bb = arrayfun(@(E1,E2)quad(@(x)x.^2./(exp(x/0.5172)-1),E1,E2),EI,EG);
Best Answer