Reading data into matrices with labels for rows and columns

For questions and discussion related to reading in and working with data.
Marcus
Posts: 21
Joined: Wed May 19, 2010 5:12 am

Reading data into matrices with labels for rows and columns

Unread post by Marcus »

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
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

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

Unread post by TomDoan »

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||
Post Reply