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

조회 수: 2 (최근 30일)
Mehran Mustafa
Mehran Mustafa . 2020년 1월 15일
댓글: Mehran Mustafa . 2020년 1월 16일
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.
  댓글 수: 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 Import from MATLAB에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by