Probelm with 'writecell'
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I just want to delet first line form my data.
It's .csv file, and raw data has two line for text and others are number.
This is what i trying to do.
m = readcell('rawdata.csv');
m(1,:) = [];
writecell(m, 'modified_data.csv');
but it doesn't work.
thanks for your help.
0 Commenti
Risposte (2)
Star Strider
il 10 Lug 2019
Try this:
m = readcell('rawdata.csv');
writecell(m(2:end,:), 'modified_data.csv');
If that does not work, upload (attach) ‘rawdata.csv’ so we can experiment with it.
1 Commento
Guillaume
il 10 Lug 2019
If the only thing you're trying to do is remove the first line of a text file, then parsing the file (with csvread, readcell, or any similar function) is completely overkill and just slows you down.
filecontent = fileread('rawdata.csv');
without1stline = regexp(filecontent, '(?<=[\n\r]+)[^\n\r].*', 'match', 'once')
fid = fopen('modifed_data.csv', 'w');
fwrite(fid, without1stline);
fclose(fid);
2 Commenti
Guillaume
il 15 Lug 2019
[filename, path] = uigetfile('*.csv'); %ask user for a csv file
assert(~isequal(filename, 0), 'No file selected. Aborting');
filecontent = fileread(fullfile(path, filename)); %read file, using full path
without1stline = regexp(filecontent, '(?<=[\n\r]+)[^\n\r].*', 'match', 'once'); %remove 1st line of file
[~, base, extension] = fileparts(filename); %split input file name into base and extension
newfilename = [base, '_modified', extension]; %append '_modified' to base filename and add extension back
fid = fopen(fullfile(path, newfilename), 'w'); %create new file
fwrite(fid, without1stline);
fclose(fid);
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!