|
-
May 10th, 2003, 05:55 PM
#1
Matrix Assigment
I have a matrix to assign its'value
the values are stored in a data file,
for example :
1 2 3 4 5
5 6 7 8 9
.....
How can I read the values from file
into the Matrix?Thanks.
-
May 10th, 2003, 05:58 PM
#2
which type of variable are the matrix elements and how are them stored in the file?
-
May 10th, 2003, 06:08 PM
#3
Originally posted by Doctor Luz
which type of variable are the matrix elements and how are them stored in the file?
I want to know if there is a good way to deternmine
from the data file, for example 2 rows 5 cols and
alloc enough memory for the array and then read
data sequentially from the data file and assign each value to the corresponding position?Thanks.
-
May 10th, 2003, 06:15 PM
#4
to alloc data you should know which type of data to alloc. int, float, double....
And How was this data stored in file, for example if the data was stored as formatted text, binary ....
-
May 10th, 2003, 06:23 PM
#5
Originally posted by Doctor Luz
to alloc data you should know which type of data to alloc. int, float, double....
And How was this data stored in file, for example if the data was stored as formatted text, binary ....
I know the data type for example double,the data
is stored in a simple text file,the format of is like:
1.0 2.0 3.0 4.0 5.0
3.0 4.0 5.0 6.0 4.0
the first row of the data from the text file goto the first column of the matrix;the second row goto the second
column of the matrix.Is there any convienient way
to do that?Thanks a lot!
-
May 10th, 2003, 06:28 PM
#6
The numbers have a defined length or they are separeted by spaces ' ' or other character?
-
May 10th, 2003, 06:34 PM
#7
Originally posted by Doctor Luz
The numbers have a defined length or they are separeted by spaces ' ' or other character?
Yes,the row number or column number are
fixed for now,and they are separated by space' '.
-
May 10th, 2003, 06:52 PM
#8
First alloc in memory the matrix elements. For example if the matrix has ( row X col) elements you can do:
Code:
matrix = (double **) calloc (rows, sizeof (double **));
for (int i = 0; i < rows; i++)
matrix [i] = (double *) calloc (cols, sizeof (double));
After this You can read each text row, extract it's elements taking into account the ' ' is the separator and them to the matrix[row][col] double element.
This FAQ explains how to convert a string to a numeric type.
dont forget to free(matrix) after use it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|