Z
zhong huang
Could anyone help me?
I have a matrix file (matrix.dat) which looks like this:
0.97 0.97 0.97 0.81 0.8 0.53 0.54 0.54 0.36 0.41 0.5 0.46 0.61 0.86
0.95 0.7 0.86 0.81 0.57 0.55 0.55 0.46 0.46 0.47 0.63 0.7 0.9 1.05
0.98 0.88 0.86 0.89 0.85 0.57 0.6 0.49 0.46 0.37 0.53 0.43 0.79 1.06
0.87 0.67 1 0.71 0.79 0.5 0.51 0.69 0.45 0.63 0.61 0.58 0.78 1.06
1.14 0.69 1.23 0.63 0.92 0.6 0.46 0.55 0.32 0.38 0.46 0.47 0.68 0.82
1.16 0.77 1.02 0.8 0.85 0.47 0.54 0.55 0.37 0.43 0.57 0.53 0.64 0.87
1.15 0.81 0.89 0.67 0.77 0.48 0.59 0.48 0.4 0.34 0.51 0.5 0.59 0.91
I want to open the file and put each element in a 2d array. My code is
like this:
==code start==
$file = "matrix.dat";
open(FILE,$file);
@data = <FILE>;
#each line is an element of the @data, loop through and separate each row in a bigger 2d array
for ($m=0;$m<scalar(@data)-1;++$m){
while($data[$m]){
for $j(0..13){ #there are 14 elements in each row
$td_array[$m][$j] = [split('\t',$data[$m]);
}
}
print "@td_array;
==code end==
It doesn't work. A working script is much appreciated.
Zhong
I have a matrix file (matrix.dat) which looks like this:
0.97 0.97 0.97 0.81 0.8 0.53 0.54 0.54 0.36 0.41 0.5 0.46 0.61 0.86
0.95 0.7 0.86 0.81 0.57 0.55 0.55 0.46 0.46 0.47 0.63 0.7 0.9 1.05
0.98 0.88 0.86 0.89 0.85 0.57 0.6 0.49 0.46 0.37 0.53 0.43 0.79 1.06
0.87 0.67 1 0.71 0.79 0.5 0.51 0.69 0.45 0.63 0.61 0.58 0.78 1.06
1.14 0.69 1.23 0.63 0.92 0.6 0.46 0.55 0.32 0.38 0.46 0.47 0.68 0.82
1.16 0.77 1.02 0.8 0.85 0.47 0.54 0.55 0.37 0.43 0.57 0.53 0.64 0.87
1.15 0.81 0.89 0.67 0.77 0.48 0.59 0.48 0.4 0.34 0.51 0.5 0.59 0.91
I want to open the file and put each element in a 2d array. My code is
like this:
==code start==
$file = "matrix.dat";
open(FILE,$file);
@data = <FILE>;
#each line is an element of the @data, loop through and separate each row in a bigger 2d array
for ($m=0;$m<scalar(@data)-1;++$m){
while($data[$m]){
for $j(0..13){ #there are 14 elements in each row
$td_array[$m][$j] = [split('\t',$data[$m]);
}
}
print "@td_array;
==code end==
It doesn't work. A working script is much appreciated.
Zhong