早教吧作业答案频道 -->其他-->
matlab 用subplot和hold on 以后是这个效果,试验程序运行出来是个效果:clear all;n=20;a=(round(100*rand(n,1))/100)*2.2-0.9;figure;hold on;subplot(2,2,1);plot(1:n,a,'rx');xlabel('样本数');ylabel('生化化验
题目详情
matlab 用subplot和hold on 以后是这个效果,
试验程序运行出来是个效果:

clear all;
n=20;
a=(round(100*rand(n,1))/100)*2.2-0.9;
figure;hold on;subplot(2,2,1);
plot(1:n,a,'rx');
xlabel('样本数');
ylabel('生化化验值');
title('样本数据:生化化验值');hold on;
pause;
%%先验概率
P=[0.9 0.1];
%%作类条件概率曲线p(x/wi)
x=-0.9:0.01:1.3;
px(1,:)=(1/(sqrt(2*pi)*0.3))*exp(-0.5*(x/0.3).^2);
px(2,:)=(1/(sqrt(2*pi)*0.18))*exp(-0.5*((x-1)/0.1).^2);
figure;hold on;subplot(2,2,2);
plot(x,px(1,:),'b',x,px(2,:),'r--');
xlabel('生化化验值');
ylabel('概率密度');
title('类条件概率密度曲线');
axis tight;hold on;
pause;
%%做后验概率曲线
for i=1:2
pwx(i,:)=px(i,:)*P(i)./(px(1,:)*P(1)+px(2,:)*P(2));
end
figure(3);hold on;subplot(2,2,3);
plot(x,pwx(1,:),'b',x,pwx(2,:),'r--');
xlabel('生化化验值')
ylabel('后验概率')
title('后验概率曲线');
axis tight;hold on;
pause
%损失函数
r=[0,1000,000; 200,000,0];
%作条件风险曲线
for i=1:2
R(i,:)=r(i,1)*pwx(1,:)+r(i,2)*pwx(2,:);
end
figure;hold on;subplot(2,2,4);
plot(x,R(1,:),'b',x,R(2,:),'r--');
xlabel('生化化验值');
ylabel('条件风险');
title('条件风险曲线')
axis tight;hold on;
pause
%%计算给定检验值的类条件概率密度
for j=1:n
s=a(j);
PXW1=spline(x,px(1,:),s);
PXW2=spline(x,px(2,:),s);
PXW=[PXW1,PXW2];
disp('样本');
s
%%计算后验概率?判别输出
for i=1:2
Pwx(i)=PXW(i)*P(i)/(PXW(1)*P(1)+PXW(2)*P(2));
end
%计算条件风险,判别输出
for i=1:2
Rx(i)=r(i,1)*Pwx(1)+r(i,2)*Pwx(2);
end
disp('条件风险R(ai|x)=')
Rx
plot(x,R(1,:),'b',x,R(2,:),'r--');
xlabel('生化化验值');
ylabel('条件风险');
title('条件风险曲线')
hold on
plot(s,Rx(1),'or',s,Rx(2),'ob');
axis tight;
hold off
if Rx(1)w(j,1)=s;
disp('正常人')
else
w(j,2)=s;
disp('感染病人')
end
pause;
end
disp('')
disp('正常人 感染病人 ')
w
试验程序运行出来是个效果:

clear all;
n=20;
a=(round(100*rand(n,1))/100)*2.2-0.9;
figure;hold on;subplot(2,2,1);
plot(1:n,a,'rx');
xlabel('样本数');
ylabel('生化化验值');
title('样本数据:生化化验值');hold on;
pause;
%%先验概率
P=[0.9 0.1];
%%作类条件概率曲线p(x/wi)
x=-0.9:0.01:1.3;
px(1,:)=(1/(sqrt(2*pi)*0.3))*exp(-0.5*(x/0.3).^2);
px(2,:)=(1/(sqrt(2*pi)*0.18))*exp(-0.5*((x-1)/0.1).^2);
figure;hold on;subplot(2,2,2);
plot(x,px(1,:),'b',x,px(2,:),'r--');
xlabel('生化化验值');
ylabel('概率密度');
title('类条件概率密度曲线');
axis tight;hold on;
pause;
%%做后验概率曲线
for i=1:2
pwx(i,:)=px(i,:)*P(i)./(px(1,:)*P(1)+px(2,:)*P(2));
end
figure(3);hold on;subplot(2,2,3);
plot(x,pwx(1,:),'b',x,pwx(2,:),'r--');
xlabel('生化化验值')
ylabel('后验概率')
title('后验概率曲线');
axis tight;hold on;
pause
%损失函数
r=[0,1000,000; 200,000,0];
%作条件风险曲线
for i=1:2
R(i,:)=r(i,1)*pwx(1,:)+r(i,2)*pwx(2,:);
end
figure;hold on;subplot(2,2,4);
plot(x,R(1,:),'b',x,R(2,:),'r--');
xlabel('生化化验值');
ylabel('条件风险');
title('条件风险曲线')
axis tight;hold on;
pause
%%计算给定检验值的类条件概率密度
for j=1:n
s=a(j);
PXW1=spline(x,px(1,:),s);
PXW2=spline(x,px(2,:),s);
PXW=[PXW1,PXW2];
disp('样本');
s
%%计算后验概率?判别输出
for i=1:2
Pwx(i)=PXW(i)*P(i)/(PXW(1)*P(1)+PXW(2)*P(2));
end
%计算条件风险,判别输出
for i=1:2
Rx(i)=r(i,1)*Pwx(1)+r(i,2)*Pwx(2);
end
disp('条件风险R(ai|x)=')
Rx
plot(x,R(1,:),'b',x,R(2,:),'r--');
xlabel('生化化验值');
ylabel('条件风险');
title('条件风险曲线')
hold on
plot(s,Rx(1),'or',s,Rx(2),'ob');
axis tight;
hold off
if Rx(1)
disp('正常人')
else
w(j,2)=s;
disp('感染病人')
end
pause;
end
disp('')
disp('正常人 感染病人 ')
w
▼优质解答
答案和解析
除了第一个subplot前面的figure留着,后面的figure语句都去掉,否则没画一个内容,都新开一个窗口.
看了 matlab 用subplo...的网友还看了以下:
Matlab程序:错误在哪里建立函数文件fun5.mfunction dy=fun5(t,y)dy 2020-05-16 …
求一个简单的方程组的解我怎么都求不出来,求出来的解带入进去不对,请回答这个问题的验证一下你的答案, 2020-05-16 …
当对正态总体均值检验时,如果总体方差未知则应该进行( )。A.Z检验B.F检验C.t检验D.χ2检验 2020-05-21 …
∮1dx/(x^2+y^2+z^2)ds,其中,曲线x=(e^t)sinty==(e^t)cost 2020-06-03 …
看一道函数解答题(超简单的)已知f(x+1)=x^2+2x,求f(x)令x+1=t,则t=x-1所 2020-06-06 …
已知f(x-1)=x^2-4x,求函数f(x),f(2x+1)的解析式令t=x-1,则有:x=t+ 2020-06-17 …
分解因式(高级)(1-7t-7t²-3t³)(1-2t-2t²-t³)-(t+1)ⁿn=6找到了求 2020-07-03 …
当x∈[0,4]求定积分∫1/(1+√x)dx设√x=t则t∈[0,2]dx=2tdt原式=2∫t 2020-07-23 …
某种海洋生物身体的长度f(t)(单位:米)与生长年限t(单位:年)满足如下的函数关系:f(t)=10 2020-11-21 …
某同学做验证动量守恒定律的实验,将A、B两滑块在一水平长直气垫导轨上相碰,用频闪照相机分别在t0=0 2020-11-25 …