MATLAB, ASCII. TextScan? ImportData? to load? none of them work

I need to import ASCII files into MATLAB and then read them. These are the functions that I came across:

1) load(filename) does not work: it says: "The number of columns in line 2 of the ASCII file should be the same as the previous lines"

2) textscan(file, '-ascii') returns something like "An empty array of cells: 1-by-0

3) importdata(file) returns "data: [2x1 double], textdata: [4x1 cell], colheaders {'* LOS ='}. It really works as suggested by georgesl, but treats the full text as a unique column: like me can I skip the header and then split the data into 2 columns?

I noticed that everything is fine if I convert the ascii file to one, but I have many files (over 100) that need to be developed.

What should I do?

thanks

+4
source share
3 answers

You can read the whole file in a line using fileread

 text = fileread( filename ); 

Then you can analyze it yourself using regexp

+2
source

I like the approach mentioned by Shay, but usually use the textscan command

 data = textscan(fid, '%s', 'Delimiter', '\n') 

so that I get an array of row cells. Makes things easier to handle if you are concerned about line numbers.

+1
source
 [filename pathname] = uigetfile({'*.txt'}, 'Select File'); fullpathname = strcat (pathname, filename); A = importdata(fullpathname,''); value =getfield(A, 'data'); 

enjoy it!

0
source

All Articles