Using fprintf to write multiple data into one file using a for loop

12 次查看(过去 30 天)
I have several folders each filled with 10-20 sets of data stored separately as csv files. The data is in the form of vectors in 2 columns [x y]. I have imported the data using Dir, I want to be able to process each piece of data one at a time using a for loop (as some of the processing involves a manual input), then save each vector of data in a single file in separate columns using fprintf. The vectors are all of different sizes, e.g. sample1 (1000x54), sample2 (755x2), sample3 (900x2) sample4 (1150x2)... and so on.
Any suggestions?
  1 个评论
Guillaume
Guillaume 2015-7-24
编辑:Guillaume 2015-7-24
I would rethink your format. text files are inherently a linear (row) format. The only way to write / read columns is by reading all the rows.
It would make more sense to me to write your vectors by row.
Otherwise, your only option is to prepare the content of the file in memory and write it to the file all at once. Reading a file with columns of different length is also going to be more complicated than a file with rows of different length.

请先登录,再进行评论。

回答(1 个)

Muhammad Usman Saleem
this is possible , share some data

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by