psychrometrics with Matlab

This is the second tutorial on climate visualization using Matlab, particularly on plotting weather data on a psychrometric chart.

Although architects are most familiar with psychrometric chart to understand comfort zone and identify appropriate passive design strategies, psychrometrics is more commonly used by mechanical engineers to study air and water vapor mixture for active mechanical devices to condition air.

Tools like Autodesk’s Ecotect Weather Tool or Climate Consultant are typically sufficient for architects to study comfort zone and passive design strategies. However, for active applications, we need to be able to enter our own data points, such as ones that come from mechanical specs or material properties.

4 scripts 2 data files are included in this distribution.

  • Make sure all 6 files are mapped into your Matlab path. Easiest way is to put all the files into your My Documents\Matlab folder, or on OSX > Documents\Matlab
  • Open ReadEPW.m  This is an updated version and does not require you to manually input the file path.
  • Click Run and locate the desired Energy+ Weather file
  • Open EPW2Hourly.m and click Run
  • Type in command:
    This will create a scatter plot of all the hourly values of dry bulb temperature and absolute humidity.
  • To separate all the data by months, use the command
    psychro(dbt(aug),ahm(aug ),0,0,’scatter’);

  • Sometimes having all the hourly data is not very useful because there’s simply too much information. Run the EPW2Daily.m file, this will reshape the 1×8760 matrix to 24×365, and we can easily find the daily maximum and minimum, and plot the diurnal changes.
  • Type in command:
    This will give you a line plot of all the diurnal changes. The line will start at the higher temperature and end at the lower temperature.
  • Once again, we can separate it into individual months with the following command
  • psychro(dbtMax(apr),dbtMin(apr),ahmMax(apr),ahmMin(apr),’line’);

If you get an error like this one

??? Error using ==> fgetl at 44
Invalid file identifier.  Use fopen to generate a valid file
Error in ==> ReadEPW at 16
loc = fgetl(fid);

That means Matlab is not recognizing the folder of your EPW file. Go to File > Set Path and locate the folder.

To set a different color for each month and automatically save the charts, you can do the following.

%written and copyrighted by Ted Ngai
%version 0.1 Mar 2011

xSize = 6; %This is the horizontal size of the figure
ySize = 4; %This is the vertical size of the figure
months = {1:31, 32:59, 60:90, 91:120, 121:151, 152:181, 182:212, 213:243, 244:273, 274:304, 305:334, 335:365};
monthstr = {'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'};
for x = 1:12

%get current month
month = cell2mat(months(x))';

%get min/max of month

%set color value

%plot graph

xlabel(cell2mat(monthstr(x))); %.. and label for the y axis
%ylabel('temperature (\circC)'); %Input the labels for the x axis

currentFig = gcf;
currentAxes = gca;

set(currentFig, 'PaperUnits', 'inches'); %change paperspace units here (also line 25)
set(currentFig, 'PaperSize', [xSize ySize]);
set(currentFig, 'PaperPositionMode', 'manual');
set(currentFig, 'PaperPosition', [0 0 xSize ySize]);
set(currentFig, 'Units', 'inches'); %change paperspace units here too
set(currentFig, 'Position', [0, 0, xSize, ySize]);

axis([minmon maxmon 0 120]);

hgexport(currentFig,fn); %Change the filename here

clear xSize ySize currentFig currentAxes fn temp maxmon minmon month ;

3 Responses to “psychrometrics with Matlab”

  1. Kat says:

    This is brilliant. Thank you!

  2. Ji says:

    Dear ted,

    May I ask the Matlab approach to color the dots as shown in your charts?


  3. wsy says:

    good nice