CodeCodeCode

ENGR132: HW07 - class6a_activity2

May 6th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.06 KB | None | 0 0
  1. %  Program Description: Draws data from a text file and creates a
  2. %  histogram.
  3.  
  4. % --- INPUTS ---
  5. %Reads the text file into a string array.
  6. hist_data = textread('journal_diam.txt');
  7.  
  8. % --- CALCULATIONS ---
  9. %Takes the mean.
  10. fprintf('\nMean of data: %f\n', mean(hist_data));
  11. %Finds the median value.
  12. fprintf('Median of data: %f\n', median(hist_data));
  13. %Finds the standard deviation.
  14. fprintf('Standard deviation of data: %f\n', std(hist_data));
  15. %Finds the minimum value.
  16. fprintf('Minimum of data: %f\n', min(hist_data));
  17. %Finds the maximum value.
  18. fprintf('Maximum of data: %f\n', max(hist_data));
  19.  
  20. % --- OUTPUTS ----
  21. %Creates a histogram with given data.
  22. hist(hist_data)
  23. xlabel('Journal diameters (in)');
  24. ylabel('Number of samples');
  25. title('Frequency of journal diameters.');
  26. grid;
  27.  
  28. %It is definitely easier to use the MATLAB histogram creation method as it
  29. %is much, much faster.  However, MATLAB's histogram function seems to
  30. %create a graph that changes slightly as the data changes.  Also, the bars
  31. %could offset themselves and make the graph strange to read.
Advertisement
Add Comment
Please, Sign In to add comment