function [g]=matrix(f) %f=5
a=2*pi*f;
m=1;
for n=1:3
g11(m)=1+n*a;
g12(m)=2*n-a;
g21(m)=sqrt(n);
g22(m)=n/2+a;
m=m+1;
end
g1=[g11(1),g12(1);g21(1),g22(1)];
g2=[g11(2),g12(2);g21(2),g22(2)];
g3=[g11(3),g12(3);g21(3),g22(3)];
g(1,:,:)=g1; g(2,:,:)=g2;g(3,:,:)=g3;
end
调用g1时,使g1=reshape(g(1,:,:),2,2);
调用g2时,使g2=reshape(g(2,:,:),2,2);
调用g3时,使g1=reshape(g(3,:,:),2,2)即可!
如果有多个多元矩阵时,子函数时候应当是
function [g1 g2 g3]=matrix(f) %f=5
a=2*pi*f;
m=1;
for n=1:3
g11(m)=1+n*a;
g12(m)=2*n-a;
g21(m)=sqrt(n);
g22(m)=n/2+a;
m=m+1;
end
g1=[g11(1),g12(1);g21(1),g22(1)];
g2=[g11(2),g12(2);g21(2),g22(2)];
g3=[g11(3),g12(3);g21(3),g22(3)];
end
调用的时候应当写[G0 G1 G2]=matrix(5);
则G0, G1, G2分别为子函数中的g0, g1, g2.