Filter löschen
Filter löschen

Exporting Lines from One Text File to Another

3 Ansichten (letzte 30 Tage)
jgillis16
jgillis16 am 27 Okt. 2015
Bearbeitet: Jan am 27 Okt. 2015
I have the following code written to copy certain lines from one text file:
contents = fileread('observedsn.txt');
[starts, stops] = regexp(contents, ...
'^([^|]*\|){24}(Ib|Ib/c|Ic|II|IIP|IIn|IIPec)\|.*$', ...
'start', 'end', 'lineanchors', 'dotexceptnewline');
How would I proceed to export these text lines to a new text file?
I have attached my text file.

Akzeptierte Antwort

Jan
Jan am 27 Okt. 2015
Bearbeitet: Jan am 27 Okt. 2015
NL = char(10);
fid = fopen('Output.txt', 'W'); % Uppercase 'W' for buffering!
if fid == -1, error('Cannot open file for writing.'); end
for k = 1:length(starts)
fwrite(fid, contents(starts(k):stops(k)), 'uchar');
fwrite(fid, NL, 'uchar');
end
fclose(fid);

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export 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!

Translated by