0
votes

I know there are various ways of importing data from a text file, but I'm not sure which one is the more straight forward. I've attempted to use import data, but I'm coming across an issue.

The data looks like this:

Track File : C:\Tasl\Img0000059.TRK
-----------------------------------

       X       Y    PHI  RANGE    DIP    MAJ     MIN      XT      ZT      M2
   192.7    30.0  286.2    0.0    0.0   5.60    4.42    6.59  108.50    1.32 
    73.4   689.2  210.8    0.0    0.0  34.61   29.20   34.61* 108.50    2.31*
    26.2   475.1   80.4    0.0    0.0   5.66    5.14    5.03* 108.50    0.44*
    43.3   674.3   61.7    0.0    0.0  18.95   10.85   27.42  108.50    2.16...

Which seems to work, but when I look at the data part of the output structure, it only contains rows up to (and including the first one that contains *. It also shows these values as NaN.

Is there a way I can get Matlab to ignore these *, or is there a better approach to importing this data?

Thanks

1
Preprocess (find and replace etc.) the file to delete all * before importing? - Dev-iL
This is a quick work around for a small number of files, thanks! - LNKirkham

1 Answers

0
votes

I ended up doing this:

fidInFile = fopen(filename,'r');            %# Open input file for reading
fidOutFile = fopen([filename '_nostars'],'w');  %# Open output file for writing
nextLine = fgets(fidInFile);                %# Get the first line of input
while nextLine >= 0                         %# Loop until getting -1 (end of file)
  nextLine = strrep(nextLine,'*','');  %# Replace wordA with wordB
  fprintf(fidOutFile,'%s',nextLine);        %# Write the line to the output file
  nextLine = fgets(fidInFile);              %# Get the next line of input
end
fclose(fidInFile);                          %# Close the input file
fclose(fidOutFile);                         %# Close the output file

Then I used 'importdata' on the new file. I could then run this on hundreds of files rather than manually going through each one and using find and replace.