Add data to .csv file using matlab
92 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Harshita K
le 5 Oct 2020
Commenté : Sudhakar Shinde
le 6 Oct 2020
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/371296/image.png)
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.
0 commentaires
Réponse acceptée
Sudhakar Shinde
le 5 Oct 2020
Modifié(e) : Sudhakar Shinde
le 5 Oct 2020
data = {'DateTime1' 'UserName1' 'Path1' 'Remark1'};
data1= {'DateTime2' 'UserName2' 'Path2' 'Remark2'};
Data = [data;data1];
writecell( Data, 'test.csv');
3 commentaires
Plus de réponses (2)
Jon
le 5 Oct 2020
Modifié(e) : Jon
le 5 Oct 2020
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 commentaires
Jon
le 5 Oct 2020
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
le 5 Oct 2020
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');
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!