Create a Matlab program to analyze and graph the two data files (BB.txt and PP.t
ID: 3822218 • Letter: C
Question
Create a Matlab program to analyze and graph the two data files (BB.txt and PP.txt):
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.
6. Produce 3 graphs:
A. 3 dimensional graph showing PP levels by location on a 20x20 grid. Recommend using a mesh plot of PP.
B. 3 dimensional graph showing BB levels by location on a 20x20 grid. Recommend using a mesh plot of BB.
C. PP vs. BB. Recommend: plot(PP(:), BB(:), ‘.’)
Note: all of above graphs should have appropriate titles and axis labels.
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.3057
2.31
2.31
2.31
2.31
2.3145
2.3145
2.3145
2.3147
2.3147
2.3147
2.3149
2.3149
2.3149
2.32
2.32
2.32
2.32
2.32
2.3245
2.3247
2.3247
2.3249
2.3249
2.33
2.3345
2.3349
2.34
2.3547
2.3649
2.4049
2.4049
2.4949
2.7047
2.8047
PP.txt:
3.3
3.4
3.4
3.4
3.4
3.5
3.5
3.5
3.5
3.5
3.5
3.5
3.6
3.6
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.7
3.8
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
3.9
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.1
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.3
4.4
4.4
4.4
4.4
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.5
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.7
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
4.9
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.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.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
fileID = fopen('BB.txt','r');
formatSpec = '%f';
A = fscanf(fileID,formatSpec)
max_A=max(A)
min_A=min(A)
avg_A=mean(A)
%fprintf("Maximum from BB.txt is %f ",max_A);
fileID2 = fopen('PP.txt','r');
B = fscanf(fileID2,formatSpec)
max_B=max(B)
min_B=min(B)
avg_B=mean(B)
%fprintf("Maximum from PP.txt is %f ",max_B);
fprintf('============================================================= ');
fprintf('For BB.txt %8s %8s %8s ','Minimum','Maximum','Average');
fprintf('%8.4f %8.4f %8.4f ', [min_A,max_A,avg_A]')
fprintf('============================================================= ');
fprintf('For PP.txt %8s %8s %8s ','Minimum','Maximum','Average');
fprintf('%8.4f %8.4f %8.4f ', [min_B,max_B,avg_B]')
fprintf('============================================================= ');
Output :
=============================================================
For BB.txt
Minimum Maximum Average
0.1451 2.8047 1.3397
=============================================================
For PP.txt
Minimum Maximum Average
3.3000 6.0000 4.8195
=============================================================