Combining y columns of several x,y matrices into one matrix

4 views (last 30 days)
OK, I've edited my request with more detail: I have ten (1554x2) .csv files of x,y data (I've attached eight here, for some reason couldn't load the other two!). I want to combine all the y columns of these into one matrix, with the names of each column as the first row. How do I do this please? It's OK if I don't have the names of the files included in the matrix, as long as the order in which they are added to the matrix is the same as the list of files? Thank you!

Accepted Answer

Stephen23
Stephen23 on 24 Sep 2018
Edited: Stephen23 on 24 Sep 2018
"How do I do this please?"
By following the guidelines in the MATLAB documentation:
And concatenating the data vertically after the loop:
M = vertcat(C{:})
Numeric arrays do not store character data, so you cannot add headers as the first row of a numeric matrix. You could use a table, which has headers, but makes accessing the data slightly more complex. Your choice.
Note that you will have to make some decisions about how to read the files, depending on some information which you have not told us, e.g. how the files are named, what sequence you want the files imported in, what file format they use (including any delimiter, etc (I know you wrote CSV, but we regularly get people calling tab-delimited or semi-colon-delimited files "CSV" files)). Basically without an explanation of the filenames and their required order and a sample file or two, there is not much more that we can do for you. You can upload sample files by editing your question and clicking the paperclip button.
  4 Comments
Michel Nieuwoudt
Michel Nieuwoudt on 24 Sep 2018
Hi Stephen,Thank you so much for your answer :) and for the natsortfiles code. I will apply these! Best wishes, Michel
Stephen23
Stephen23 on 25 Sep 2018
@Michel Nieuwoudt: I hope that it helped. Remember to accept my answer!

Sign in to comment.

More Answers (1)

Michel Nieuwoudt
Michel Nieuwoudt on 25 Sep 2018
Thank you! have done :)

Categories

Find more on Structures 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!