Page 1 of 1

Reading data into matrices with labels for rows and columns

Posted: Wed Jun 27, 2012 10:13 am
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

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

Posted: Wed Jun 27, 2012 10:58 am
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||