Advertisement
Guest User

code lab2

a guest
Oct 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.37 KB | None | 0 0
  1. %Valerie, Chino, Nick, Solomon, and David
  2. %AERO 321 Lab 2
  3. %10/10/2018
  4.  
  5. close all ;
  6. clear all ;
  7. clc ;
  8.  
  9. %% Question 4
  10. disp('Question 4')
  11.  
  12. numDataPoints = 100;
  13. [t,data] = serial_reader(numDataPoints);
  14.  
  15. Data1 = data(:,1);
  16. Time = t;
  17.  
  18. d = data(:,1);
  19. plot(t(1:2:end),d(1:2:end),'r',t(2:2:end),d(2:2:end),'b')
  20. legend('damp','orig')
  21. %Calculating the desired quantities:
  22. %1) Mean
  23. Mean1 = mean(Data1) ;
  24. disp(['The mean value is', num2str(Mean1)])
  25.  
  26. %2) Standard Deviation
  27. SD1 = std(Data1) ;
  28. disp(['The standard deviation is', num2str(SD1)])
  29.  
  30. %3) Standard Error of the Mean
  31. SDError1 = std(Data1)/sqrt(length(Data1)) ;
  32. disp(['The standard error of the mean is', num2str(SDError1)])
  33.  
  34. %4) Goodness of Fit
  35. [h, p, stats] = chi2gof(Data1) ;
  36. ChiSquared1 = stats.chi2stat ;
  37. disp(['The chi squared value is', num2str(ChiSquared1)])
  38.  
  39. %Plotting Data vs. Time
  40. figure
  41. plot(Time, Data1)
  42. title('Distance vs. Time')
  43. xlabel('Time (s)')
  44. ylabel('Distance (cm)')
  45.  
  46. %% Question 5
  47. disp('Question 5')
  48. Data2 = fopen('____.mat') ;
  49.  
  50.  
  51. %Calculating the desired quantities:
  52. %1) Mean
  53. Mean2 = mean(Data2) ;
  54. disp(['The mean value is', num2str(Mean2)])
  55.  
  56. %2) Standard Deviation
  57. SD2 = std(Data2) ;
  58. disp(['The standard deviation is', num2str(SD2)])
  59.  
  60. %3) Standard Error of the Mean
  61. SDError2 = std(Data2)/sqrt(length(Data2)) ;
  62. disp(['The standard error of the mean is', num2str(SDError2)])
  63.  
  64. %4) Goodness of Fit
  65. [h, p, stats] = chi2gof(Data2) ;
  66. ChiSquared2 = stats.chi2stat ;
  67. disp(['The chi squared value is', num2str(ChiSquared2)])
  68.  
  69. %Plotting Data vs. Time
  70. plot(Time, Data2)
  71. title('Distance vs. Time')
  72. xlabel('Time (s)')
  73. ylabel('Distance (cm)')
  74.  
  75. %% Question 6
  76. disp('Question 6')
  77. Data3 = fopen('____.mat') ;
  78.  
  79. %Part a
  80. %Calculating the desired quantities:
  81. %1) Mean
  82. Mean3 = mean(Data3) ;
  83. disp(['The mean value is', num2str(Mean3)])
  84.  
  85. %2) Standard Deviation
  86. SD3 = std(Data3) ;
  87. disp(['The standard deviation is', num2str(SD3)])
  88.  
  89. %3) Standard Error of the Mean
  90. SDError3 = std(Data3)/sqrt(length(Data3)) ;
  91. disp(['The standard error of the mean is', num2str(SDError3)])
  92.  
  93. %4) Goodness of Fit
  94. [h, p, stats] = chi2gof(Data3) ;
  95. ChiSquared3 = stats.chi2stat ;
  96. disp(['The chi squared value is', num2str(ChiSquared3)])
  97.  
  98. %Plotting Data vs. Time
  99. plot(Time, Data3)
  100. title('Distance vs. Time')
  101. xlabel('Time (s)')
  102. ylabel('Distance (cm)')
  103.  
  104. %Part b
  105.  
  106. %Part c
  107.  
  108. %% Question 7
  109. disp('Question 7')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement