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

1 view (last 30 days)
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 Comment
Guillaume
Guillaume on 24 Jul 2015
Edited: Guillaume on 24 Jul 2015
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.

Sign in to comment.

Answers (1)

Muhammad Usman Saleem
Muhammad Usman Saleem on 24 Jul 2015
this is possible , share some data

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!