Writing to CSV file help
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
So I have a CSV file with a list of variables with various assignments, so for example: *note these are each in on cell each
a = 5464,,,,,,,
b = 657578,0.46454,0,85976
c = 46,,,,,,
d = 45345
e = 0,5,6,8,,,,,,,
I want to filter the csv file so that it removes the ,,,,,, and then reformat this so that it will then become
a = 5464; b = 657578,0.46454,0,85976; c = 46; d = 45345; e = 0,5,6,8;
in once cell
I have the idea to use a regexp to filter the commas but I dont know how to filter it specifically.
2 Kommentare
Walter Roberson
am 17 Sep. 2015
When you say that they are in one cell each, do you mean one line each? Or do you mean that in the CSV file each of these expressions was enclosed in double-quotes "" to mark that the commas did not indicate the end of the value?
Rodriguez Pham
am 17 Sep. 2015
Bearbeitet: Rodriguez Pham
am 17 Sep. 2015
Antworten (1)
Walter Roberson
am 17 Sep. 2015
data = {'a = 5464,,,,,,,'; 'b = 657578,0.46454,0,85976'; 'c = 46,,,,,, '; 'd = 45345'; 'e = 0,5,6,8,,,,,,,'}
trimmed_data = regexprep(data, ',+\s*$', '');
joined_data = [strjoin(trimmed_data(:).', '; '), ';'];
1 Kommentar
Kirby Fears
am 18 Sep. 2015
Rodriguez,
Your answer is right here.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!