Matlab_data_structures

Matlab_data_structures - Matlab Data Structures Dr. Antonio...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Virginia Tech (copyright A.A. Trani) Matlab Data Structures Dr. Antonio A. Trani Professor Dept. of Civil and Environmental Engineering
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Virginia Tech (copyright A.A. Trani) Why Learn Data Structures? Engineers need to manipulate large amounts of data Data sometimes comes in a variety of formats Data is both numeric and character or “string” data Matlab has two important structures that you should be familiar with: Struct arrays Cell arrays 2
Background image of page 2
Virginia Tech (copyright A.A. Trani) Recall: Reading Data Files Using the Textcan Command Using the Textscan Command Here is a sample script to read a text file containing data on bridges of the world fid = fopen (‘bridges_of_the_world_short’) readHeader = textscan (fid, ‘%s’, 4, ‘delimiter’, ‘|’); readData = textscan (fid, '%s %s %f %f'); fclose(fid); 56a
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Virginia Tech (copyright A.A. Trani) Data File (bridges_of_the_world) Name | Country | Completed | Length (m) Mackinac United-States 1957 8038 Xiasha China 1991 8230 Virginia-Dare-Memorial United-States 2002 8369 General-Rafael-Urdaneta Venezuela 1962 8678 Sunshine-Skyway United-States 1987 8851 Twin-Span United-States 1960 8851 Wuhu-Yangtze-River China 2000 10020 Third-Mainland Nigeria 1991 10500 Seven-Mile United-States 1982 10887 San-Mateo-Hayward United-States 1967 11265 Leziria-Bridge Portugal 2007 11670 Confederation Canada 1997 12900 Rio-Niterol Brazil 1974 13290 Kam-Sheung Hong Kong 2003 13400 Penang Malaysia 1985 13500 Vasco-da-Gama Portugal 1998 17185 Bonnet-Carre-Spillway United-States 1960 17702 Chesapeake-Bay-Bridge-Tunnel United-States 1964 24140 Tianjin-Binhai China 2003 25800 Atchafalaya-Swamp-Freeway United-States 1973 29290 Donghai China 2005 32500 Manchac-Swamp United-States 1970 36710 Lake-Pontchartrain-Causeway United-States 1956 38422 Header Data 56b
Background image of page 4
Virginia Tech (copyright A.A. Trani) Explanations of the Matlab Script fid = fopen (‘bridges_of_the_world_short’) fid - file ID assigned by Matlab fopen - “opens” (or reads) the text file called ‘bridges_of_the_world’ readHeader = textscan (fid, ‘%s’, 4, ‘delimiter’, ‘|’); variable readHeader will store the contents of the first row in the file (‘bridges_of_the_world’) textscan reads the first row of the file using ‘%s’,4 (four string variables) with ‘delimiter’ = ‘|’ Name | Country | Completed | Length (m) Mackinac United-States 1957 8038 Xiasha China 1991 8230 Virginia-Dare-Memorial United-States 2002 8369 56c
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Virginia Tech (copyright A.A. Trani) Explanations of the Matlab Script readData = textscan (fid, '%s %s %f %f'); variable readData will store the contents of the information starting in the second row (until the end) in the file (‘bridges_of_the_world’) textscan reads the row data using ‘%s %s’ two string variables and two ‘%f %f’ numerical variables (f stands for floating point) fclose(fid); fclose(fid) closes the file (fid) opened at the beginning
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/01/2012 for the course CEE 3804 taught by Professor Aatrani during the Spring '07 term at Virginia Tech.

Page1 / 43

Matlab_data_structures - Matlab Data Structures Dr. Antonio...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online