Create a Matlab program to analyze and graph the two data files (BB.txt and PP.t
ID: 2082424 • Letter: C
Question
Create a Matlab program to analyze and graph the two data files (BB.txt and PP.txt, they will be given below and you can copy them directly):
1. Read data files BB.txt and PP.txt into Matlab.
2. Find the average PP for all of the data in PP.txt and display it using a fprintf statement in a nice column form.
3. Find the maximum PP and minimum PP for all of the data in PP.txt and display them using a fprintf statement in column form.
4. Find the average BB level for all of the data in BB.txt and display it using the fprintf statement.
5. Find the maximum BB and minimum BB for all of the data in BB.txt and display them using the fprintf statement.
BB.txt:
0.1451
0.1827
0.1827
0.1827
0.1827
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.2496
0.2696
0.2796
0.2896
0.2896
0.2896
0.2896
0.2896
0.2896
0.2996
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.3645
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4589
0.4689
0.5277
0.5377
0.5477
0.5477
0.5477
0.5577
0.5577
0.5577
0.5577
0.5577
0.5577
0.5677
0.5677
0.5677
0.5677
0.5677
0.5677
0.5677
0.5677
0.5677
0.5677
0.5777
0.5777
0.58
0.5807
0.5817
0.5827
0.5855
0.5877
0.5877
0.5977
0.6777
0.6777
0.7156
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7273
0.7577
0.7973
0.8156
0.8156
0.8273
0.8777
0.8777
0.8956
0.9056
0.9056
0.9056
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9156
0.9256
0.9256
0.9356
1.0527
1.0527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.1527
1.2512
1.2527
1.2527
1.3412
1.3512
1.3512
1.3512
1.3527
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.4512
1.5512
1.5512
1.5512
1.6049
1.627
1.627
1.627
1.627
1.727
1.727
1.727
1.727
1.727
1.747
1.757
1.807
1.807
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.827
1.847
1.887
1.9047
1.927
2.0049
2.1
2.1045
2.1045
2.1045
2.1045
2.1047
2.1047
2.1047
2.1049
2.1049
2.11
2.1149
2.1647
2.2045
2.2045
2.2045
2.2047
2.2047
2.2047
2.2047
2.2047
2.2047
2.2049
2.205
2.21
2.21
2.21
2.2147
2.235
2.26
2.2645
2.27
2.27
2.2749
2.2749
2.28
2.2845
2.2847
2.29
2.2945
2.2945
2.3
2.3
2.3
2.3
2.3
2.3045
2.3045
2.3045
2.3045
2.3045
2.3045
2.3045
2.3045
2.3045
2.3047
2.3047
2.3047
2.3047
2.3047
2.3047
2.3049
2.3049
2.3049
2.3049
2.3049
2.3049
2.3049
2.3049
2.3049
2.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
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.1
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.2
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.3
5.4
5.4
5.4
5.4
5.4
5.4
5.4
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.5
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.6
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.7
5.8
5.8
5.8
5.8
5.8
5.8
5.8
5.9
5.9
5.9
5.9
5.9
5.9
5.9
5.9
6
Explanation / Answer
Initially create BB.txt and PP.txt files by copying the data given in the question.
Save these 2 files and the MATLAB .m file in the same folder.
clc;
clear all;
[A]=textread('PP.txt','%f'); % Read PP.txt file
Mean_PP = mean(A); % average of PP
max(A); % max of PP
min(A); % min of PP
[B]=textread('BB.txt','%f'); % Read BB.txt file
Mean_BB = mean(B); % avergage of BB
max(B); % max of BB
min(B); % min of BB
fprintf('Average PP %4.4f',Mean_PP);
fprintf(' max PP min PP ');
fprintf('%4.4f %4.4f',max(A), min(A)); %.. %f is a format specifier
fprintf(' Average BB %4.4f',Mean_BB);
fprintf(' max BB min BB '); % introduces a new line
fprintf('%4.4f %4.4f',max(B), min(B));
MATLAB Output:
Average PP
4.8195
max PP min PP
6.0000 3.3000
Average BB
1.3397
max BB min BB
2.8047 0.1451>>