Sunspot data - use this if the other file did not work
Contents
You first need to download the data file
Download the file sunspot_data2.csv and put it in the same directory as your other m-files
Read monthly sunspot data since 1749 until right now
Note that this will write the file sunspot_data.csv into your current working directory (specified at the top of your Matlab window). Change the current directory to the directory where your own m-files are (if you don't have write permission for the current directory you will get an error message).
filename = 'sunspot_data2.csv'; T = readtable(filename); % read file, gives "table" datatype data = table2array(T); % convert to array t_midmonth = data(:,3); % column 3 is date of middle of month (in fraction of year) f = data(:,4); % sunspot numbers are in column 4 N = length(f); t = (0:N-1)/12; % we pretend data are taken at intervals of h=1/12 years plot(t,f,'.-'); axis tight % plot data xlabel('years since 1749') title('Monthly mean total sunspot number')
