필터 지우기
필터 지우기

Write/Read CSV file

조회 수: 19 (최근 30일)
Peng Zhao
Peng Zhao 2019년 7월 2일
댓글: Peng Zhao 2019년 7월 3일
I'm trying to write table into a CSV file that looks like the following:
Capture.PNG
Row 1 will be kept the same, then the other rows will be added to the file while the script is running (or added at once at the end).
I tried using writetable, csvwrite, etc... but it does not come out to what I want, and I am having trouble creating a matrix with text.
Please help. Thanks.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2019년 7월 2일
Peng - please clarify what you mean by but it does not come out to what I want. Does something get written to file? Is some data overwritten by other data? What code have you written?
Peng Zhao
Peng Zhao 2019년 7월 3일
I was not able to create a matrix with strings, for example:
I want:
x = ['one','two','three'];
but the output is:
x =
[o n e t w o t h r e e]
not
x =
[one two three]
thus when I write it into csv, the format is wrong.

댓글을 달려면 로그인하십시오.

답변 (2개)

Chirag Nighut
Chirag Nighut 2019년 7월 2일
To create a matrix with text you can create a 2D array of chars. To do that you can use the following code:
data = ['MATLAB ';'SIMULINK ';'POLYSPACE'];
celldata = cellstr(data)
chr = char(celldata)
Although before using char you should check if celldata is cell array of character vetors. Following function can help you
iscellstr
I request you to post the exact error/difficulty that you got using csvwrite and writetable. I can then try to help you get the desired results.
  댓글 수: 1
Peng Zhao
Peng Zhao 2019년 7월 3일
This is what I tried to do for the first row of the csv file:
delete Task_Import.csv
CSV1stLine = ['Type','Summary','Planned For','Filed Against','Parent','Owned By','Estimate'];
csvwrite('Task_Import.csv',CSV1stLine)
and the csv file that was generated had only one letter in each cell.
Also, for the summary column, I will need to write an sentense into the cell from user input.

댓글을 달려면 로그인하십시오.


Kaustav Bhattacharya
Kaustav Bhattacharya 2019년 7월 2일
Look at the append data section of this link. https://in.mathworks.com/help/matlab/ref/dlmwrite.html
  댓글 수: 1
Peng Zhao
Peng Zhao 2019년 7월 3일
Hello, the problem is how to write strings into csv.
Writing regular matrices was good.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by