Here are two quick example MATLAB code fragments that will read in data that is in the format:
string # # # #
This is the only format that this file can read. If your data is in a different format, you will need to adjust the FSCANF statement accordingly.
NOTE: This is only an example and is provided, as is, without additional support. For more information on any of the functions used in this MATLAB file, type "help {function-name}".
r=0;
x=0;
fid = fopen('data.dat','rt');
while(x~=(-1))
x=fgetl(fid);
r=r+1;
end
r = r-1;
disp(['Number of rows = ' num2str(r)])
frewind(fid);
for i = 1:r
name = fscanf(fid,'%s',1);
num = fscanf(fid,'%f %f %f %f\n')';
if(i==1)
names = name;
result = num;
else
names = str2mat(names,name);
result = [result;num];
end
end
fclose(fid);
disp(' ')
disp('Data read in successfully:')
disp(result)
disp(' ')
disp('Strings read in successfully:')
disp(names)
disp(' ')
The following code will read the data and ignore the characters,
fid = fopen('data.dat','r');
b = fscanf(fid,'%*s %g %g %g %g');
b=[reshape(b,4,3)]'
fclose(fid);