fork download
  1. % Load the temperature data
  2. data = readtable('temperature.dat', 'Delimiter', ',', 'ReadVariableNames', false);
  3.  
  4. % Extract year and monthly temperatures
  5. years = data.Var1; % First column (Year)
  6. monthly_temps = data{:, 2:13}; % Columns 2 to 13 (Jan to Dec)
  7.  
  8. % (a, b) Find the warmest month and year
  9. [max_temp, max_index] = max(monthly_temps(:));
  10. [year_index, month_index] = ind2sub(size(monthly_temps), max_index);
  11. p6a = month_index; % Month (1 for Jan, ..., 12 for Dec)
  12. p6b = years(year_index); % Year
  13.  
  14. % (c) Count occurrences of temperatures > 75°F between 1900 and 2000
  15. count_above_75 = sum(monthly_temps(years >= 1900 & years <= 2000, :) > 75, 'all');
  16. p6c = count_above_75;
  17.  
  18. % (d) Count occurrences of temperatures > 75°F in summer (Jun, Jul, Aug) between 1900 and 2000
  19. summer_months = monthly_temps(years >= 1900 & years <= 2000, 6:8); % Columns for Jun, Jul, Aug
  20. count_summer_above_75 = sum(summer_months > 75, 'all');
  21. p6d = count_summer_above_75;
  22.  
  23. % (e) Compute the annual cycle (average temperature for each month)
  24. annual_cycle = mean(monthly_temps, 1); % Average for each month
  25. figure(3);
  26. bar(1:12, annual_cycle);
  27. title('Annual Cycle of Temperature');
  28. xlabel('Months (1 = Jan, 2 = Feb, ..., 12 = Dec)');
  29. ylabel('Average Temperature (°F)');
  30. p6e = 'See figure 3';
  31.  
  32. % (f) Identify the month with the warmest average temperature
  33. [max_avg_temp, max_avg_month_index] = max(annual_cycle);
  34. p6f = sprintf('On average, the temperature peaks in the month of %d.', max_avg_month_index);
  35.  
  36. % (g) Write the annual cycle to a file named annual.cycle.dat
  37. annual_data = [(1:12)', annual_cycle'];
  38. writetable(array2table(annual_data), 'annual.cycle.dat', 'WriteVariableNames', false);
  39. p6g = evalc('type("annual.cycle.dat")'); % Display the content of the file
  40.  
  41. % (h) Compute the annual mean temperature
  42. annual_mean_temp = mean(monthly_temps, 2); % Average for each year
  43. figure(4);
  44. hold on;
  45. plot(years, annual_mean_temp, 'k-', 'LineWidth', 2); % Annual mean temperature
  46. scatter(years(annual_mean_temp > 65), annual_mean_temp(annual_mean_temp > 65), 'ro'); % Years warmer than 65°F
  47. scatter(years(annual_mean_temp < 60), annual_mean_temp(annual_mean_temp < 60), 'bd'); % Years cooler than 60°F
  48. title('Annual Mean Temperature Variation Over the Years');
  49. xlabel('Year');
  50. ylabel('Mean Temperature (°F)');
  51. legend('Mean Temperature', 'Temp > 65°F', 'Temp < 60°F');
  52. p6h = 'See figure 4';
  53.  
  54. % (i) Determine the trend in temperature over the years
  55. if mean(annual_mean_temp) > mean(annual_mean_temp(1:floor(end/2))) % Compare first and second half of data
  56. p6i = 'On average, the temperature in San Diego gets warmer over the years.';
  57. else
  58. p6i = 'On average, the temperature in San Diego gets cooler over the years.';
  59. end
  60.  
  61. % Display results
  62. disp(['Warmest Month: ', num2str(p6a)]);
  63. disp(['Warmest Year: ', num2str(p6b)]);
  64. disp(['Count > 75°F (1900-2000): ', num2str(p6c)]);
  65. disp(['Count > 75°F in Summer (1900-2000): ', num2str(p6d)]);
  66. disp(p6e);
  67. disp(p6f);
  68. disp(p6g);
  69. disp(p6h);
  70. disp(p6i);
  71.  
Success #stdin #stdout #stderr 0.34s 49944KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
warning: the 'readtable' function is not yet implemented in Octave

Please read <https://w...content-available-to-author-only...e.org/missing.html> to learn how you can
contribute missing functionality.
error: 'readtable' undefined near line 2 column 8
error: called from
    /home/afMsP7/prog.octave at line 2 column 6