Week 3 – Data Input/Output & Plotting

Learning Outcomes By the end of this week, students will be able to:

  1. Understand and use different data types in MATLAB.
  2. Import and export data between MATLAB and common formats (CSV, Excel, MAT).
  3. Organize data using arrays, tables, and timetables.
  4. Perform simple data cleaning and transformations.
  5. Produce basic 2D plots and customise them.
  6. Save figures and outputs for reports.

Suggested Readings

  • Frain, MATLAB for Economics and Econometrics, Ch. 3 (Data I/O) & Ch. 5 (Plotting).
  • MatlabCheatSheet.pdf - plotting.

In-Class Activities

  • Import data using
  • online sources: API vs direct URL.
  • CSV/Excel files.
  • Convert imported data into MATLAB tables and timetables.
  • Diagnose missing values and handle them (rmmissing, fillmissing).
  • Compute year-on-year GDP growth from quarterly data.
  • Plot GDP levels and YoY growth with:
  • Titles, axis labels, and legends.
  • Automatic colour + varying line styles for multiple series.
  • Save outputs:
  • Cleaned dataset to .mat and .csv.
  • Plots as .png and .fig.

Homework / Practice

  • Download real GDP (constant prices, 2015=100) for all available countries from the World Bank (via API or direct CSV).
  • Build a panel dataset in MATLAB and convert to a table.
  • Compute for each country:
    • Log of GDP
    • YoY growth rates
  • Select some countries of your choice
  • Produce and save plots:
    • Real GDP levels on the same plot with different colours/styles +legend.
    • Each country YoY growth rate on a different subplot plus a line showing the average growth rate over the sample.
    • Export the cleaned panel dataset and figures.

Files