Skip empty line and alphabet
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
1 1 -1 1 1 -1 -1 1 1 1 -1 1
1 -1 1 -1 -1 1 1 1 1 -1 1 1
sss
1 1 1 -1 1 -1 1 -1 -1 -1 -1 1
rtyyjjjj
1 -1 1 -1 -1 -1 1 1 -1 -1 -1 1
1 1 -1 1 1 -1 -1 -1 1 -1 1 -1
1 -1 1 1 1 1 1 -1 -1 -1 1 -1
I want to store the data into matlab as matrix, skipping the empty line and lines with alphabets.
How do i use textscan to perform this task or is there any better way? I used textscan and i get a= 8X1 cell.
Please help. Thank you .
0 Kommentare
Antworten (2)
Image Analyst
am 14 Mai 2016
Use fgetl() and then skip any lines where the first character of the line you just read in is not a numeral.
0 Kommentare
Walter Roberson
am 14 Mai 2016
textscan() of a file is not really suitable for that. Instead:
filecontent = fileread('YourFile.txt');
filecontent = regexprep(filecontent, {'^\s+', '^.*[^-+0123456789 \n].*', '\n\n'}, {'','','\n'}, 'lineanchors','dotexceptnewline');
YourData = cell2mat( textscan(filecontent, repmat('%f',1,12), 'CollectOutput', 1) );
This textscan()'s the string that has had the bad data thrown away.
This expression considers data to be bad if it contains anything other than spaces, plus sign, minus sign, or digits. In particular it does not take into account decimal points or floating point, and it does not know about the possibility of comments after the end of a line.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!