How can I write to a CSV file in separated columns and without any commas?

35 次查看(过去 30 天)
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!

回答(3 个)

Christopher Wallace
编辑:Christopher Wallace 2018-7-13
csvwrite('matlabdandata2.csv', [frames, time, cycle])
  9 个评论
Image Analyst
Image Analyst 2018-7-14
编辑:Image Analyst 2018-7-14
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
Image Analyst 2018-7-13
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 个评论
Image Analyst
Image Analyst 2018-7-13
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
Ece Su Ildiz 2018-7-14
It gives the following;
data =
113.0000 -5.7143 0
119.0000 -4.4898 0
124.0000 -3.4694 0
129.0000 -2.4490 0
139.0000 -0.4082 0
154.0000 2.6531 2.0000
169.0000 5.7143 4.0000
184.0000 8.7755 6.0000
199.0000 11.8367 8.0000
214.0000 14.8980 10.0000
229.0000 17.9592 12.0000
244.0000 21.0204 14.0000
259.0000 24.0816 16.0000
273.0000 26.9388 18.0000
289.0000 30.2041 20.0000
304.0000 33.2653 22.0000
318.0000 36.1224 24.0000
332.0000 38.9796 26.0000
349.0000 42.4490 28.0000
363.0000 45.3061 30.0000
379.0000 48.5714 32.0000
393.0000 51.4286 34.0000
408.0000 54.4898 36.0000
423.0000 57.5510 38.0000
438.0000 60.6122 40.0000
453.0000 63.6735 42.0000
467.0000 66.5306 44.0000
483.0000 69.7959 46.0000
498.0000 72.8571 48.0000
513.0000 75.9184 50.0000
527.0000 78.7755 52.0000
542.0000 81.8367 54.0000
558.0000 85.1020 56.0000
573.0000 88.1633 58.0000
588.0000 91.2245 60.0000
602.0000 94.0816 62.0000
618.0000 97.3469 64.0000
632.0000 100.2041 66.0000
647.0000 103.2653 68.0000
663.0000 106.5306 70.0000
Name Size Bytes Class Attributes
data 40x3 960 double
Just used first 3 column. XLS file is also attached. Thank you very much.
  6 个评论
Image Analyst
Image Analyst 2018-7-14
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
Ece Su Ildiz 2018-7-15
I meant the separation of columns by saying "CSV file in separated columns". Also I am talking about the dot separator (in each cell) as decimal point separator. I am trying to obtain the exact output as shown in MATLAB matrix and I don't want any commas. It is set up for Turkey and Turkey uses commas for decimal points. Maybe that's the reason. I'll check. Thank you again Sir.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by