Write cell data to excel or text file in a specific format
조회 수: 5 (최근 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!
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!