matlab中输入一组数据怎么求每个数据的概率
3个回答
展开全部
A数组是个例子,程序你看一下吧,有什么不懂的再问吧!
clear;clc
A=[1 1 1 1 1 3 3 3 3 5 5 5]
B=unique(A)
c=zeros(size(B));
for i=1:length(B)
c(i)=length(find(A==B(i)));
end
c
p=c./sum(c)
clear;clc
A=[1 1 1 1 1 3 3 3 3 5 5 5]
B=unique(A)
c=zeros(size(B));
for i=1:length(B)
c(i)=length(find(A==B(i)));
end
c
p=c./sum(c)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用蒙特卡洛模拟:
n=10000
%试验次数,越大越精确
c=zeros(n,1);
%存储每次试验的结果
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%开始试验
for
k=1:n
%按a的密度分布对a抽样
r=rand;
%产生一个服从u(0,1)的随机数;
if
r<0.3
a=0;
elseif
r<0.3+0.3
a=0.1;
else
a=0.15;
end
%对b抽样
r=rand;
%产生一个服从u(0,1)的随机数;
if
r<0.2
b=0;
elseif
r<0.2+0.3
b=0.1;
else
b=0.15;
end
c(k)=a+b;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%试验结果分析%%%%%%%%%%%%%%%
w=unique(c)
%c的所有值
n=length(w);
num=zeros(n,1);
%用于存储c的所有值的频数
for
k=1:n
num(k)=sum(c==w(k));
end
num
%频数
p=num/n
%频率
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=10000
%试验次数,越大越精确
c=zeros(n,1);
%存储每次试验的结果
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%开始试验
for
k=1:n
%按a的密度分布对a抽样
r=rand;
%产生一个服从u(0,1)的随机数;
if
r<0.3
a=0;
elseif
r<0.3+0.3
a=0.1;
else
a=0.15;
end
%对b抽样
r=rand;
%产生一个服从u(0,1)的随机数;
if
r<0.2
b=0;
elseif
r<0.2+0.3
b=0.1;
else
b=0.15;
end
c(k)=a+b;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%试验结果分析%%%%%%%%%%%%%%%
w=unique(c)
%c的所有值
n=length(w);
num=zeros(n,1);
%用于存储c的所有值的频数
for
k=1:n
num(k)=sum(c==w(k));
end
num
%频数
p=num/n
%频率
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数组中的是什么类型的数据啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询