Reading data into matrices with labels for rows and columns

For questions and discussion related to reading in and working with data.

Reading data into matrices with labels for rows and columns

Postby Marcus » Wed Jun 27, 2012 10:13 am

Hi,

I'm trying to read data into symmetric matrices. To keep track of my calculations I would like to read in also labels for columns and rows.
I have tried the READ instruction and it should be possible to read in labels for at least either rows or columns but I haven't been very successful sofar.

Any help would be greatly appreciated.

best

Marcus
Marcus
 
Posts: 11
Joined: Wed May 19, 2010 5:12 am

Re: Reading data into matrices with labels for rows and colu

Postby TomDoan » Wed Jun 27, 2012 10:58 am

You should be able to do that using the LEFT, TOP, and RIGHT options on READ. You just need to read the data using one of the "spreadsheet" formats (like PRN for a text file) which load the data first so that you can select specific ranges. (The default FORMAT=FREE reads as it goes and doesn't have the same level of control over what gets processed). For example:

open data labelmatrix.txt
dec vect[labels] v(3)
read(right=1,top=2) v
dec symm s(3,3)
read(left=2,right=4,top=2,format=prn) s

data:

a b c
a 1 2 3
b 2 3 4
c 3 4 5

will give you V=||"a","b","c"|| and S=||1|2,3|4,5,6||
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm


Return to Data: Reading, Writing, Transforming

Who is online

Users browsing this forum: No registered users and 0 guests