📄 simu2data.m
字号:
function SIMU2DATA
%simulate a 2-way data (matrix)
%chrom is a matrix with peak height,peak position and peak variance of several chromatography peaks
%such as chrom =[1 20 1;1.5 40 0.8;2 70 1.2]
% global X
clear,clc
%%%parameter of 2_way data%%%%%%%%%%%%%%%%%%%%%%%%%%%
h = [0.04 0.12 0.06 0.07 0.05 0.08 0.10 0.12 0.14];%0.08 0.05];
sgm =[ 3 8 5 6 5 4 3 5 6];%3 2 ];
% h = [ 0.04 0.05 0.06 0.03];
% sgm =[ 3 3 3 3 ];
% h1 =[ 1.0000 0.8 0.5 0.5];
% cen1 = [ 54 23 45 26];
% sgm1 = [ 5.0000 3 4 7];
% h2 =[ 0.9000 0.7 0.8 0.7];
% cen2 = [ 34 46 12 52];
% sgm2 = [ 7.6000 6.8 6 5];
% h3 =[ 1.0000 1.0];
% cen3 = [ 14 55];
% sgm3 = [ 6.0000 2];
%h4=[ 0.5000 0.9000 0.9 ];
%cen4 = [48 59 52];
%sgm4 = [6.20000 7.6000 7];
noise = 0.00500;
% num_w =60;
num_t =100;
%%%%%chromatograpy peaks'postion%%%%%%%%%%%%%%%%%%%%
%cen=[35 45 55 65 75 ];
%cen=[35 50 65 80 95 ];
cen=[ 35 55 23 65 45 52 24 32 75];%53 59] ;
% cen=[ 26 31 38 42] ;
%cen=[35 60 85 110 135] ;
%cen=[35 65 95 125 155] ;
%cen=[35 68 101 134 165 ] ;
%cen=[35 69 103 137 171 ] ;
%cen=[35 72 109 146 183 ] ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m=size(h,2);
% n=size(h1,2);
% if m~=n
% errordlg('色谱和光谱对应的组分数(即谱峰数目)必须相等!');return;
% end
% m=size(cen,2);
% n=size(cen1,2);
% if m~=n
% errordlg('色谱和光谱对应的组分数(即谱峰数目)必须相等!');return;
% end
% m=size(sgm,2);
% n=size(sgm1,2);
% if m~=n
% errordlg('色谱和光谱对应的组分数(即谱峰数目)必须相等!');return;
% end
%xmax1=round(1.2*max(chrom(:,2)));
%xmax2=round(1.2*max(spec(:,2)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%simulation programme%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t=1:80;
for i=1:m
for j=1:num_t
yij(i,j)=h(i)*exp(-(j-cen(i))^2/(2*sgm(i)^2));
end
end
purechromy=yij';
%
% for i=1:n
% for j=1:num_w
% x(j,i)=h1(i)*exp(-(j-cen1(i))^2/(2*sgm1(i)^2))+h2(i)*exp(-(j-cen2(i))^2/(2*sgm2(i)^2));%+h3(i)*exp(-(j-cen3(i))^2/(2*sgm3(i)^2));
% end
% end
%
% simuspecy=x;
% purespecy=simuspecy;
% y=yij'*simuspecy';%%%a 2_way data without noise%%%
%y=y+max(max(y))*randn([num_t,num_w])*noise;%%%with noise
% plot(y);
% [m,n]=size(simuspecy);
% simuspecy=simuspecy';
% figure(3)
% subplot(2,2,1);
% plot(simuspecy(1,:) );
%
% subplot(2,2,2);
% plot(simuspecy(2,:) );
%
% subplot(2,2,3);
% plot(simuspecy(3,:) );
%
% subplot(2,2,4);
% plot(simuspecy(4,:) );
%%%%%%%%%%%%Mass spectrum simulation~%%%%%%%%%%%%%%%%%%%%%%
load('stds2.mat');
X=S;
S=[];
uu=size(X,1);
for i=1:9
value(i)=ceil(rand*uu);
S1=X(value(i),:);
S=[S;S1];
end
S(1,:)*S(2,:)'/(norm(S(1,:),2)*norm(S(2,:),2))
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
simuspecy=S;
save('simuspecy.mat','simuspecy')
y=yij'*S;
y=y+max(max(y))*randn(100,200)*noise;
figure(3)
plot(y);
% [m,n]=size(S);
figure(2)
subplot(2,1,1);
bar(S(1,:),0.001);
xlabel(int2str(value(1)))
subplot(2,1,2);
bar(S(2,:),0.001);
xlabel(int2str(value(2)))
% subplot(2,2,3);
% bar(S(3,:),0.001);
% xlabel(int2str(value(3)))
% subplot(2,2,4);
% bar(S(4,:),0.001);
% xlabel(int2str(value(4)))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%save the 2_way data%%%%%%%%%%%%%%%%
X=y;
save('X.mat','X')
% save simuspecy.mat
%save ('D:\MATLAB6p5\work\data\X','X','-mat');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
% plot(sum(yij)','c');
plot(yij(1,:)/norm(yij(1,:),2))
hold on;
plot(yij(2,:)/norm(yij(2,:),2))
% plot(yij'/norm(yij',2))
xlabel('time scan point');
ylabel('absorption A');
drawnow;
% figure(1)
% plot(purespecy);
% xlabel('spectral scan point');
% ylabel('absorption A');
% drawnow;
[U,S,V]=svd(X);
U=U*S;
save('U.mat','U')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -