I want the data in the .csv file to look like this:
DateTime1 Username1 Path1 Remark1
Here, all the cells are strings and they are in a single row but 4 columns. Everytime I need to add data at the end of this .csv i.e. it should look something like this
How to I prepare this data? I really don't know how to prepare this data and add it to the csv in this manner. Can someone please help me out here?
I tried preparing the data in this way,
data = ['DateTime1' 'UserName1' 'Path1' 'Remark1'] But they got concatenated.

 채택된 답변

Sudhakar Shinde
Sudhakar Shinde 2020년 10월 5일
편집: Sudhakar Shinde 2020년 10월 5일

0 개 추천

data = {'DateTime1' 'UserName1' 'Path1' 'Remark1'};
data1= {'DateTime2' 'UserName2' 'Path2' 'Remark2'};
Data = [data;data1];
writecell( Data, 'test.csv');

댓글 수: 3

Harshita K
Harshita K 2020년 10월 5일
편집: Harshita K 2020년 10월 5일
Could you elaborate on how I can add to the end of the csv with the new set of data? This is done only if both data and data1 are created in the same instance which is not the case. Everytime I run the .m file all the information has to be added to the end of the csv in that manner.
I could make this work by reading the csv data using
data = readcell('test.csv');
data1= {'DateTime2' 'UserName2' 'Path2' 'Remark2'};
Data = [data;data1];
writecell( Data, 'test.csv');
Thank you.
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 6일
Welcome

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

추가 답변 (2개)

Jon
Jon 2020년 10월 5일
편집: Jon 2020년 10월 5일

0 개 추천

In MATLAB put the data into a table array. Then use writetable with the 'WriteMode','Append' property value pair. Please see https://www.mathworks.com/help/matlab/ref/writetable.html especially the section on adding data to end of table

댓글 수: 2

Harshita K
Harshita K 2020년 10월 5일
WriteMode isn't supported in 2019b I guess, everytime I use that, there's an error that says,
Invalid parameter name: WriteMode.
Jon
Jon 2020년 10월 5일
I didn't realize that was such a new feature. If you have it available I would recommend updating to the new version, if not just for this feature just to stay current.

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

Luciano Garim
Luciano Garim 2020년 10월 5일

0 개 추천

To import your data from a CSV file into MATLAB use the “readtable” function. The “readtable” function automatically detects the header and the number of lines to skip.
T = readtable('myfile.csv');
To add your data use dlmwrite
M = randn(4,4);
dlmwrite(T,M,'delimiter',',','-append');

댓글 수: 1

Harshita K
Harshita K 2020년 10월 5일
This works only with numbers, when I want to add strings this is how it gets populated in the csv,

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 10월 5일

댓글:

2020년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by