function mnhf_exchange_rate() %MNHF_EXCHANGE_RATE plots then interpolates Canada-US exchange rate data. ms = 10; % markersize in figure. fs = 12; % fontsize in figure. % Input exchange rate information. x represents the month of 2010; y gives % the monthly average exchange rate (amount of US$ needed to buy $1 Cdn). x = 1:1:12; y = [0.95883 0.94623 0.97751 0.99496 0.96161 0.96345 0.95906 0.96026 ... 0.96797 0.98234 0.98736 0.99231]; % Plot data. figure; hold on; box on plot(x,y,'ko','markersize',ms) set(gca,'fontsize',fs) xlim([1 12]) set(gca,'xtick',[1 2 3 4 5 6 7 8 9 10 11 12]) set(gca,'xticklabel',['J';'F';'M';'A';'M';'J';'J';'A';'S';'O';'N';'D']) xlabel('Month of 2010','fontsize',fs+4) ylabel('Monthly average exchange rate','fontsize',fs+4) title('Canada-US exchange rate','fontsize',fs+4) % Contrast different interpolation routines. xi = 1:0.05:12; yi_nearest = interp1(x,y,xi,'nearest'); plot(xi,yi_nearest,'b-.') yi_linear = interp1(x,y,xi,'linear'); plot(xi,yi_linear,'r--') yi_spline = interp1(x,y,xi,'spline'); plot(xi,yi_spline,'k-') % Add legend. legend('Raw data','Nearest neighbor','Piecewise linear','Cubic spline',... 'location','southeast')