Write cell data to excel or text file in a specific format
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have one-day travel survey data that I want to use for my project. I need to format this survey data to make it usable for my program. The raw data has several trips data which is sorted according to USER ID. Each USER makes several trips in one day, and I have sorted these user trips into a cell array, where each array holds the information for all the trips made by ONE user. Now I want to transform this rows in each cell into something like this:
[[[87 2 13 1.03333] [205 1 13 1.25]] [[120 8 3 0.0833333] [127 1 3 0.0833333]]]
Over here, this [[87 2 13 1.03333] [205 1 13 1.25]] shows all the trip data of one user, i.e. 2 trips. The next bracket encloses the trips for another user, i.e. [[120 8 3 0.0833333] [127 1 3 0.0833333]].
So I think essentially, I want all the rows in the array to be converted to a comma separated list, where each row is a list item.
Currently, the above data in MATLAB is in rows, i.e. for one user there are two rows and 4 columns. I want to make them look like above.
Could you kindly give me any hints/clues/tricks?
Thank you!
0 Commenti
Risposte (1)
Spencer Chen
il 16 Gen 2020
I'm afraid that you are not clear enough for me regarding the original format of the data, so I can only guess.
If you just want to extract every 2nd row and concatenate it columnwise, and assuming they are in a single 2D cell array:
B = [A(1:2:end,:), A(2:2:end,:)];
You can use xlswrite() to write to an Excel file. You would need to use cell2num() or otherwise convert your cell data into a matrix.
Blessings,
Spencer
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!