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.

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

2) D = randi([10,20],100,\'distributed\');

3) fileID=fopen(\'data.txt\',\'w\');

fprintf(fileID, D);

fclose(fileID);

4) fileID=fopen(\'dat.txt\',\'r\');

formatSpec = \'%d %d %d\';

sizeA = [3 Inf];

fscanf(fileID,formatSpec,SizeA);

prob_A=arrayfun(@X)length(find(A==X)),unique(A))/1000;

disp ( prob_A );

(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)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site