I have a dataset which has about 20 spectra. All 20 spectra share the same x-axis. So I have 21 columns, column 1 representing the x-axis and columns 2 to 21 representing the y values. I want to save the data 20 separate .csv files. Csvwrite just combines all the data into one large csv files which is not what I want. I want a code that can save cloumn 1 and 2 separately, 1 and 3 separately, 1 and 4 separately and so on till column 1 and 21 so that in the end I will have 20 separate csv files each having column 1 as the x-axis and the corresponding y column as y-axis.
Look forward to hearing from someone and I would really appreciate it.
Thanks.

댓글 수: 5

per isakson
per isakson 2017년 11월 10일
편집: per isakson 2017년 11월 10일
Something like this?
for jj = 2:21
csvwrite( sprintf( 'y%d.csv', jj ), M(:,[1,jj]) );
end
KSSV
KSSV 2017년 11월 10일
IT is better to have all the data in single csv files.
Curious Mind
Curious Mind 2017년 11월 10일
Thanks @per isakson. Will definitely give it a try and let you know
Curious Mind
Curious Mind 2017년 11월 10일
Please what does M stands for in your code? Is it the data file name?
per isakson
per isakson 2017년 11월 10일
편집: per isakson 2017년 11월 10일
  • M is your dataset with 21 columns
  • sprintf( 'y%d.csv', jj ) creates a filename

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

 채택된 답변

KSSV
KSSV 2017년 11월 10일

2 개 추천

A = rand(10,11) ;
%%Write each colum to different files
for i = 2:size(A,2)
filename = ['column',num2str(i),'.csv'] ;
csvwrite(filename,A(:,[1 i]))
end

댓글 수: 2

Curious Mind
Curious Mind 2017년 11월 10일
@KSSV will this save my data into 20 separate csv files? I don’t want 1 large file. Can you please explain your approach for me? Thank you
KSSV
KSSV 2017년 11월 10일
편집: KSSV 2017년 11월 10일
It is straight forward.....run a loop for each column and use csvwrite for each column with different file names. You run the above code and see. YOu can replace A with your data.

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

추가 답변 (0개)

카테고리

태그

질문:

2017년 11월 10일

편집:

2017년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by