早教吧作业答案频道 -->其他-->
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('样本数');ylabe
题目详情
matlab 用subplot和hold on 以后无法把绘图放在一个窗口里,
试验程序运行出来是个效果:
![](https://www.zaojiaoba.cn/2016-03/02/1456888795.jpg)
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
试验程序运行出来是个效果:
![](https://www.zaojiaoba.cn/2016-03/02/1456888795.jpg)
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
▼优质解答
答案和解析
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 off;
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)
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 off;
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)
看了 matlab 用subplo...的网友还看了以下:
重新排列字母,写出单词1.s,a,p,e,c,2.r,o,e,t,c,k,3.d,c,o,o,t, 2020-06-06 …
根号3sin(100πt+π/3)和sin(100πt-π/6)已知两种简谐交流电的电流强度分别为 2020-06-07 …
叨在《新华字典》上有两个读音:dāo和tāo,而在《现代汉语词典》上却有三个读音:dāo、dáo和 2020-06-16 …
公式里面缺少;是什么意思这个公式是在股票里用的:如下:MA13:=MA(C,13);MA34:=M 2020-07-23 …
写单词,这些单词打乱顺序了!:1.d,f,e,n,i,f,e,r,t,()2.g,h,o,e,t, 2020-07-26 …
推断题:现有如下反应(反应条件均不给),推断物质⑴A→B+C+D⑵C+E→C+F+D⑶D+G→H⑷ 2020-07-30 …
已知el=100sin(100πt+60°)ve2=(100πt+20°)v求(1)各电动势的最大值 2020-10-31 …
谁会用下列字母组成三个英语单词???g,a,l,o,ts,t,o,a,o,ha,s,f,t,ks,h 2020-11-01 …
一道概率的难题(大学级)电话用户在(t,t+Δt)这段时间内对电话站呼唤一次的概率等于λΔt+o(t 2020-11-30 …
一列简谐横波在弹性介质中沿x轴传播,波源位于坐标原点O,t=O时刻波源开始振动,t=3s时波源停止振 2021-01-12 …