필터 지우기
필터 지우기

How to append data or values to an existing .csv file??

조회 수: 203 (최근 30일)
Manoj Murali
Manoj Murali 2012년 2월 10일
댓글: YU Xinbo 2018년 6월 13일
hi..suppose i have a .csv file named csvfile.csv.And it has the values as follows:
23 45
69 84
48 78
12 34
so it has two colums.Now wat i need to do is to add values staring from the 3rd colum with out deleting the values in the 1st and 2nd colums..How can i do this...??Any one plz help..!!

채택된 답변

Wayne King
Wayne King 2012년 2월 10일
Use dlmwrite with 'delimiter', ',' and '-append'
M = randn(4,4);
dlmwrite('test.csv',M,'delimiter',',');
N = randn(4,4);
dlmwrite('test.csv',N,'delimiter',',','-append');
  댓글 수: 2
Manoj Murali
Manoj Murali 2012년 2월 10일
Thanx for the reply sir..but ther is a problem here...i want the values to be appended side by side..but ur code is printing it below the already present values.I want the newly appended data to be pasted in the right side of the already present data..not below it..Can u modify ur code and tell me plzz..??
khalid malik
khalid malik 2015년 5월 2일
Yes it works but it just append the data at next cell, Now if we want to append the data at desired line or col then what we need to amend in above script. I want a=[1 2 3; 4 5 6] and b=[0 9 8; 7 6 5] I want to create csv file in which b values append in file a from line 2 and col 4 Thanks

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

추가 답변 (2개)

William
William 2012년 2월 10일
Worst case you could read the current file you have
csvread(....);
Import the vectors, do you manipulation and then use
csvwrite(...)
to write it all back to a specified excel file.
  댓글 수: 2
khalid malik
khalid malik 2015년 5월 5일
how to append data in different col. rather than in rows? I have data in col. wise and want to append all together.
Rubedo
Rubedo 2017년 12월 20일
편집: Rubedo 2017년 12월 20일
This may possibly help, since csvwrite uses matrices you should configure your data as so. Assigned first column to 'a', second to 'b' and new data as 'c'.
csvwrite('test.csv', [a b c]);
This should output your data as:
23 45 1
69 84 2
48 78 3
12 34 4

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


Manoj Murali
Manoj Murali 2012년 2월 10일
using dlmwrite with an '-append' is only appending the new values below the already present values.But wat i want is to append the values to the right side of the already present values..Any one plzz answer..??
  댓글 수: 2
Mahmoud abouamer
Mahmoud abouamer 2018년 4월 4일
You can try something like dlmwrite('test.csv',M,'-append',... 'roffset',10,'coffset',11); where 10 and 11 are the rows and columns of the cell you r interested in.
YU Xinbo
YU Xinbo 2018년 6월 13일
This method also doesn't work. The row offset is not exact the location where I want to insert. It will skip the existing rows where there is data... The problem is that I have huge data need to export to a csv... a 7*60000 matrix

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by