finding probability in Matlab
14 次查看(过去 30 天)
显示 更早的评论
Hello,
I was given this question (1)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/507495/image.jpeg)
I did sovle it and here is the answer:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/507500/image.jpeg)
then I had to write a basic MATLAB code as given in Q2
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/507505/image.jpeg)
here is my start
clc;clear all; close all;
Genes1 = randi(500,1,21) %% generate 20 out of 500 genes
Genes2 = randi(500,1,21) %% secon trail of generating
C = intersect(Genes1,Genes2) %% find the common genes
N = numel(C) %% number of common genes
my question is how to find the probablity in matlab given the code above(or different one)?
0 个评论
采纳的回答
Alan Stevens
2021-2-2
编辑:Alan Stevens
2021-2-2
You could use a Monte-Carlo simulation approach. Building on your calculations we have, for example:
% Monte_Carlo calculation of probability
N = 10^4; % Number of trials
C = 0; % Initialise count
for i = 1:N
Genes1 = randi(500,1,20); %% generate 20 out of 500 genes
Genes2 = randi(500,1,20); %% secon trail of generating
CommonGenes = intersect(Genes1,Genes2); %% find the common genes
if ~isempty(CommonGenes)
C = C + 1;
end
end
p = C/N; % Probability
disp(p)
On second thoughts, randi can geerate repeated numbers. For non-repeated sets, replace
Genes1 = randi(500,1,20); %% generate 20 out of 500 genes
Genes2 = randi(500,1,20); %% secon trail of generating
by
Genes1 = randperm(500,20); %% generate 20 out of 500 genes
Genes2 = randperm(500,20); %% secon trail of generating
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hypothesis Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!