I need to put all the output of the function in vector

1 view (last 30 days)
function [Eg]= test_cal(L,U,P)
for t=-0.2:0.01:0;
xx=1:length(t);
x3 = 0.20*t^2 + 5.65e-5/cos(cos(8.92*t)) ...
+ 0.0003*t*cos(cos(8.922*t)) + ...
0.037*t^3*cos(cos(8.92*t)) - ...
0.031 - 0.31*t - 0.36*t^4;
x2 = 0.31*t + 0.002*sin(14.83*sin(t))^3 ...
+ 0.0012*sin(14.83*sin(t))^2 + ...
0.0008*sin(14.83*sin(t))/t - ...
0.0072 - 0.098*t^2 - ...
0.0015*cos(t)*sin(14.83*sin(t));
x1 = 0.36+ 2.46*t + 28.82*t^3 + ...
3.46*t^4 + 2.46*t^5*sin(sin(sin(99.88*t^2))) - ...
0.011*sin(sin(99.87*t^2));
x0 = 2.66 + 0.43*t*cos(30.07*t^2) + ...
0.015*t*cos(30.08*t^2)^2 - 0.48*t ...
- 0.73*t^2 - 0.097*cos(30.08*t^2) ...
- 1.19*t^3*cos(30.08*t^2);
a0 = 1.42e-10;
for tt=0.05:0.05:1
alpha0 = x0;
alpha1 = x1;
alpha3 = x3;
c = 1;
U=0;
kx = -2*pi/(3*a0):2*pi/(3*499.5*a0):2*pi/(3*a0);
for c = 1:1000
hk(c) = (exp(0)+exp(i*3*a0/2*kx(c))+exp(-i*(3*a0/2*kx(c)))); %h(k) for ky = 0.
z=sin(c);
H = [U,-alpha0*hk(c),-alpha1,-alpha3*hk(c); %H matrix
-alpha0*conj(hk(c)),U,-alpha3*conj(hk(c)),-alpha1;
-alpha1,-alpha3*hk(c),0,-alpha0*hk(c);
-alpha3*conj(hk(c)),-alpha1,-alpha0*conj(hk(c)),0];
E(:,c) = eig(H); %Solve the eigenvalue problem.
end
E3 =E(3,:);
E4 = E(4,:);
E2 = E(2,:);
Min = abs(E2-E3);
Eg = min(Min)
end
end
end
The output is like the following
Eg =
0.0069
Eg =
0.0069
Eg =
0.0069
Eg =
0.0069
Eg =
0.0069
Eg =
0.0069
Eg =
0.0069
Eg =
0.0069
So I need it as
Eg=[0.0069 0.0069 ...]

Accepted Answer

Walter Roberson
Walter Roberson on 12 Nov 2015
Right before the line
for tt=0.05:0.05:1
add the line
Egidx = 0;
then change the line
Eg = min(Min)
to
Egidx = Egidx + 1;
Eg(Egidx) = min(Min);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!