Automatically reading data files containing special characters in Matlab -
i import data file in matlab generated external software automatically.
this data file can contain special characters in third column @ random places. therefore, cannot utilize dlmread.
i'm figuring out how import file automatically in matlab while inserting data in matrix. also, identifying special characters , replacing them nan necessary.
here sample data better picture of problem:
naca0012 alfa = 25.00000 re = 0.000 xflap,yflap = 0.000000 0.000000 x y cp 1.00000 0.00126 0.53803 0.08399 0.04389 -7.27148 0.07278 0.04150 -8.16799 0.03346 0.02983-15.69087 0.02840 0.02771-18.03665 0.02399 0.02566-20.81862 0.00360 0.01041-95.28658 0.00238 0.00851********* 0.00141 0.00659********* 0.00070 0.00467********* 0.00025 0.00277********* 0.00003 0.00091********* 0.00003 -0.00091********* 0.00025 -0.00277-93.41611 0.00070 -0.00467-72.18787 0.00141 -0.00659-51.54605 0.00238 -0.00851-37.04853
notice how third column gets sort of 'stuck' onto second column
any appreciated since i'm kinda stuck , don't know how automatically. maybe guys can provide me piece of code it.
thanks in advance!
balraj
use textscan
3 ideas in mind:
- one needs skip first lines;
- the
*
strings treatednan
s; - in case of error close file.
hence code (assuming example data in file 'u.txt'
):
try f = fopen('u.txt'); m = textscan( f, ... '%f%f%f', inf, ... 'headerlines', 6, ... 'treatasempty', '*********', ... 'collectoutput', 1 ... ); fclose(f); catch me fclose('all'); end;
Comments
Post a Comment