Difference between revisions of "Software tutorial/Loading data in MATLAB or Python"

From Process Model Formulation and Solution: 3E4
Jump to navigation Jump to search
m
m
Line 16: Line 16:
Can read both the text and values in an Excel file.  Cell containing formulas are imported as the result of the formula value.
Can read both the text and values in an Excel file.  Cell containing formulas are imported as the result of the formula value.
| width="40%" valign="top" |
| width="40%" valign="top" |
Excel files in Python
The best Python libraries at the moment are <tt>xlrd</tt> and <tt>xlwt</tt> for reading and writing Excel files.  See [http://www.python-excel.org/ the xlrd and xlwt] website for more details and a tutorial.
|-
|-
| [http://en.wikipedia.org/wiki/Comma-separated_values Comma-separated value (CSV) files] are a standard format for many years and can be read on any system, since they are pure text files.
| [http://en.wikipedia.org/wiki/Comma-separated_values Comma-separated value (CSV) files] are a standard format for many years and can be read on any system, since they are pure text files.

Revision as of 16:59, 2 December 2010

A number of people asked me how to load data into MATLAB and Python after our class on the poor ability of spreadsheets to do serious engineering calculations.

Here are some functions that you can use in either language.

File format MATLAB Python

Excel files

xlsread(...) and xlswrite(...)

Can read both the text and values in an Excel file. Cell containing formulas are imported as the result of the formula value.

The best Python libraries at the moment are xlrd and xlwt for reading and writing Excel files. See the xlrd and xlwt website for more details and a tutorial.

Comma-separated value (CSV) files are a standard format for many years and can be read on any system, since they are pure text files. csvread(...) and csvwrite(...) CSV in Python
XML files are rapidly becoming a fairly standard import and export format for data, because it describes both the data and the nature of the data in the file.

xmlread(...) and xmlwrite(...).

XML Python