MATLAB: Gettting Data from file

.dat filecolumnfilereadrow

hey Guys, I am using the fileread command to open a (.dat-file) which has the following disinge
-31050 0.500000 1 255 1.000000 5.000000
1 1 1 31.146388 16 217.650000 J_055
2 2 512 377.706052 128 157.723000 J_015
3 3 1 1.000000 1 136.334000 I_043
4 4 8 109.402337 64 185.494000 J_022
5 5 8 137.383648 64 189.172000 J_023
... ... ... ... ... ... ...
the 1st line is the header of the file. Question; How can i get Values of 1 column ? Or of a specific field ?

Best Answer

Do you want to get a whole line or a whole column?
Column:
>> fid=fopen('test.txt');
>> A=textscan(fid,'%d %d %d %f %d %f %s','headerlines',1);
>> A{3}
ans =
1
512
1
8
8
Line:
A=textscan(fid,'%f %f %f %f %f %f %s','headerlines',1);
>> B=cell2mat(A(1:end-1));
>> B(3,:)
ans =
3.0000 3.0000 1.0000 1.0000 1.0000 136.3340