How can I write to a CSV file in separated columns and without any commas?
Mostra commenti meno recenti
I am using the following code to write in a CSV file for 10 different columns but I end up with all data in a single column and commas between each data.
dlmwrite('/Users/.../matlabdandata2.csv',[frames' time' cycle' ...],'delimiter',',','-append')
Thanks!
Risposte (3)
Christopher Wallace
il 13 Lug 2018
Modificato: Christopher Wallace
il 13 Lug 2018
csvwrite('matlabdandata2.csv', [frames, time, cycle])
9 Commenti
Ece Su Ildiz
il 13 Lug 2018
Christopher Wallace
il 13 Lug 2018
Sorry, I had the wrong command. See my edit above.
Ece Su Ildiz
il 13 Lug 2018
Christopher Wallace
il 13 Lug 2018
Can you provide the full code?
Ece Su Ildiz
il 13 Lug 2018
Modificato: Ece Su Ildiz
il 14 Lug 2018
Christopher Wallace
il 14 Lug 2018
Using this code and the data file you provided below results in the following which appears to be in separate columns.

Image Analyst
il 14 Lug 2018
But this answer gives commas between the values. Just open the csv file in a text editor and you'll see, and for some weird reason the poster didn't want commas and specifically said so. So he shouldn't use the csv extension and should use a .dat or .txt extension, and call dlmwrite() like I did in my answer.
Also, where did you get his input data with frames, times, cycles, etc.? I don't see that he attached it.
Image Analyst
il 14 Lug 2018
Modificato: Image Analyst
il 14 Lug 2018
That workbook has only 5 columns and they don't even have names that match. How are we supposed to generate the variables he called "[frames' time' cycle' ...]" which he is trying to stitch together?
And does he want 3 columns in the output text file, or 10 columns? And what does "the only problem is separating as 10 different columns" mean?
Image Analyst
il 13 Lug 2018
When you did this:
dlmwrite('/Users/.../matlabdandata2.csv', [frames' time' cycle' ...], 'delimiter', ',', '-append')
did you notice that you specified a comma as the delimiter? Why?
If you don't want a comma, specify a space or something else as the delimiter.
2 Commenti
Ece Su Ildiz
il 13 Lug 2018
Image Analyst
il 13 Lug 2018
What does this say in the command window:
data = [frames', time', cycle', ...etc....] % Stitch 10 vectors side by side.
whos data
dimensions = size(data)
Attach your data if you want people to help you.
Ece Su Ildiz
il 14 Lug 2018
6 Commenti
Image Analyst
il 14 Lug 2018
Please attach your input data with the 10 variables frames, times, cycles, etc. I don't see that you attached it.
I solved the problem of how to get rid of the comma for you, but with "the only problem is separating as 10 different columns", I can't do that unless I have your 10 variables or 10 columns.
What are you stitching together that is giving you 10 columns and describe what "separating as 10 different columns" looks like to you. What kind of output do you want from "separating as 10 different columns"?
Ece Su Ildiz
il 14 Lug 2018
Walter Roberson
il 14 Lug 2018
What are the rules for when comma should be used as the decimal separator or period should be used for the decimal separator ? You use both in several of the columns.
Ece Su Ildiz
il 14 Lug 2018
Image Analyst
il 14 Lug 2018
When you said "separator" regarding a CSV (Comma Separated Variable) file I assumed you meant the separator between the complete numbers. Now I'm wondering if you're talking about the separator between the thousands and millions groups in the number instead. Which is it?
Also I'm wondering if the columns in your table are actually strings, because I don't see why, in your first screenshot, cell F1 uses a comma but cell F2 uses a period for the decimal point.
What is your "region" (country) that your computer is set up for in your settings/control panel? Is it one of those countries that uses commas instead of dots for decimal points?
Ece Su Ildiz
il 15 Lug 2018
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


