Write cell data to excel or text file in a specific format

7 次查看(过去 30 天)
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!

回答(1 个)

Spencer Chen
Spencer Chen 2020-1-16
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
  1 个评论
Mehran Mustafa
Mehran Mustafa 2020-1-16
Thank you so much for your reply.
I'll try to make it clearer.
I have sorted each travel day in nested cells as follows:
In the above screenshot, each cell is ONE DAY or ONE USER, with several trips saved in the nexted cells as shown below:
Now I don't know how to save this into something like i want:
[[[1215,1230,1.32100000000000,1,20,19] [1320,1345,3.44000000000000,19,40,11] [1615,1645,5.26300000000000,11,1,1]] [[845,910,9.10500000000000,1,20,19] [1045,1110,9.05400000000000,19,1,1]]]
I hope I was able to make it a little more clear.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by