MATLAB Data Analysis and Trigonometric Plotting
Classified in Computers
Written on in
English with a size of 2.6 KB
MATLAB Statistical Analysis of Student Weights
Analyze the weight of 30 students to find the minimum, maximum, average, standard deviation, and plot a histogram.
>> a=[ 71 82 65 75 77 91 59 84 89 81 73 91 82 75 96 85 69 76 81 92 84 79 77 95 81 79 84 85 76 82]
a = Columns 1 through 12
71 82 65 75 77 91 59 84 89 81 73 91
Columns 13 through 24
82 75 96 85 69 76 81 92 84 79 77 95
Columns 25 through 30
81 79 84 85 76 82
>> max(a)
ans = 96
>> min(a)
ans = 59
>> mean(a)
ans = 80.5333
>> std(a)
ans = 8.4516
>> hist(a)Plotting Trigonometric Functions in MATLAB
Follow these steps to plot trigonometric functions:
- Plot the value of the cosine within [0, 2π] with a step of π/20.
- Label the axes and add a title.
- Add the sine function to that graph using the hold command.
- Place legends to distinguish both graphics.
>> x=0:pi/20:2*pi
x = Columns 1 through 9
0 0.1571 0.3142 0.4712 0.6283 0.7854 0.9425 1.0996 1.2566
Columns 10 through 18
1.4137 1.5708 1.7279 1.8850 2.0420 2.1991 2.3562 2.5133 2.6704
Columns 19 through 27
2.8274 2.9845 3.1416 3.2987 3.4558 3.6128 3.7699 3.9270 4.0841
Columns 28 through 36
4.2412 4.3982 4.5553 4.7124 4.8695 5.0265 5.1836 5.3407 5.4978
Columns 37 through 41
5.6549 5.8119 5.9690 6.1261 6.2832
>> y=cos(x)
y = Columns 1 through 9
1.0000 0.9877 0.9511 0.8910 0.8090 0.7071 0.5878 0.4540 0.3090
Columns 10 through 18
0.1564 0.0000 -0.1564 -0.3090 -0.4540 -0.5878 -0.7071 -0.8090 -0.8910
Columns 19 through 27
-0.9511 -0.9877 -1.0000 -0.9877 -0.9511 -0.8910 -0.8090 -0.7071 -0.5878
Columns 28 through 36
-0.4540 -0.3090 -0.1564 -0.0000 0.1564 0.3090 0.4540 0.5878 0.7071
Columns 37 through 41
0.8090 0.8910 0.9511 0.9877 1.0000
>> plot(x,y)
>> xlabel('x')
>> ylabel('cos(x)')
>> ylabel('cos(x)')
>> plot(x,y)
>> title('cosine of x')
>> xlabel('x')
>> ylabel('cos(x)')
>> hold
Current plot held
>> z=sin(x)
z = Columns 1 through 9
0 0.1564 0.3090 0.4540 0.5878 0.7071 0.8090 0.8910 0.9511
Columns 10 through 18
0.9877 1.0000 0.9877 0.9511 0.8910 0.8090 0.7071 0.5878 0.4540
Columns 19 through 27
0.3090 0.1564 0.0000 -0.1564 -0.3090 -0.4540 -0.5878 -0.7071 -0.8090
Columns 28 through 36
-0.8910 -0.9511 -0.9877 -1.0000 -0.9877 -0.9511 -0.8910 -0.8090 -0.7071
Columns 37 through 41
-0.5878 -0.4540 -0.3090 -0.1564 -0.0000
>> plot(x,z)
>> legend('cos(x)','sin(x)')
>> ylabel('y')