Mat structure to csv
조회 수: 7(최근 30일)
표시 이전 댓글
I have a mat structure and I need to convert it to csv. I tried writecsv, but it gives me an empty csv. Could you give me some ideas? The file is from page: https://zenodo.org/record/2654460#.Y8_6h3bMKF5, for 2015. Thanks.
댓글 수: 2
The info in the question you linked to reminded me that there is also the writestruct function, that will write a structure directly to file. However, the structure here doesn't meet the internal data requirements for that function to operate on it.
편집: the cyclist 2023년 1월 24일
I downloaded the first file on that page, which is EXIOBASE_3rx_aggLandUseExtensions_1995_pxp.mat, and then uploaded it to MATLAB.
The contents of that file is two structure arrays. Each of these structure arrays contains multiple fields (as described in that documentation link).
Some of those fields are 2-dimensional arrays (that could be saved to CSV files). But some are 3-dimensional arrays, which you would need code to parse and save.
There is no trivial way to just save everything as a CSV.
댓글 수: 4
dpb 2023년 1월 24일
There are some instances where the writematrix function creates a file that does not
represent the input data exactly. You will notice this when you use the readmatrix
function to read that file. The resulting data might not have the exact same format
or contents as the original array. If you need to save your array and retrieve it
at a later time to match the original array exactly, with the same data and organization,
then save it as a MAT-file. writematrix writes inexact data in the following instances:
writematrix writes out numeric data using long g format, and categorical or character
data as unquoted text.
writematrix writes out arrays that have more than two dimensions as two
dimensional arrays, with the trailing dimensions collapsed.
What does this mean, exactly...let's create a simple example 3D array with 1,2,3 on each 2x2 plane...
>> type M.csv
You see it wrote the 2x2 arrays concatenated together on two lines/records, the size(M,1).
So, the TC array would be 214 (3rd dimension) 200x214 2D arrrays written horizontally.
What would OP consider should be the format of higher-dimension arrays in a text file? He doesn't provide any guidance in what even would expect the result to be.
Alternatively, of course, one could do as @the cyclist says and parse the array and write each plane to a sheet in a given workbook if were to use Excel; a .csv file doesn't have any concept of sheets.
Find more on Spreadsheets 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!