2 Using Matlab generate a 100by100 matrix each element in th
(2). Using Matlab generate a 100-by-100 matrix, each element in this matrix is a random integer from 10 to 20.
(3). Using Matlab write the matrix in problem (2) to a txt file called ’data.txt’
(4). Load data from ’data.txt’. If you want to choose three numbers from this data(It doesn’t matter which three numbers you choose), what are the probabilities of choosing those three numbers? Calculate three probabilities respectively and provide the code.
Sample Output(If the numbers I want to choose are 10 15 17):
The probability of choosing 10 is p1
The probability of choosing 15 is p2
The probability of choosing 17 is p3
p1, p2, and p3 are probabilities of choosing 10, 15, and 17, keep four decimal places for those three numbers
Solution
r=randi([10,20],100);
f=fopen(\'data.txt\',\'w\')
fprintf(f,r)
fclose(f)
formatspec(\'%d\',\'%d\',\'%d\');
a=fscan(f,formatspec)
fclose(f)
p1=a[0]/100
p2=a[1]/100
p3=a[2]/100
disp(p1,p2,p3)
