h5read variables within table (matlab class table) from .mat files not working
조회 수: 8 (최근 30일)
이전 댓글 표시
Reading (numerical, logical, char) variables from nested structs in .mat files with h5read works fine. It saves a lot of time if you only need a few variables from a big (> 1 GB) .mat file.(Loading a 20 GB .mat file takes very, very long. If it's compressed even longer.) (I store big data within one big nested structure, that is saved in a .mat file. It contains all kinds of variables and datatypes. Among them nice tables.)
I can't get it to work to h5read variables within table (matlab class table) from .mat files.
2 questions:
- Has anyone got a solution for this problem using h5read? (I already know I could workaround via table2struct(tbl) before saving)
- Are there alternatives to quickly read variables from a table (or the whole table), that is deeply nested within a struct in a .mat file?
답변 (1개)
Shubham
2023년 3월 10일
Hi Janis,
Regarding your first question, it is possible to use the h5read function to read variables within a table that is deeply nested within a struct in a .mat file. However, it requires some knowledge of the file's structure and careful use of the h5info function to determine the path to the desired variable. Here is an example code snippet that demonstrates how to read a variable named "myVar" from a table that is nested within a struct in a .mat file:
% Open the .mat file using the h5info function
matInfo = h5info('myFile.mat');
% Determine the path to the desired variable
tablePath = '/myStruct/myTable';
varPath = [tablePath '/myVar'];
% Use h5read to read the variable
myVar = h5read('myFile.mat', varPath);
Regarding your second question, there are several alternatives to quickly read variables from a table (or the whole table) that is deeply nested within a struct in a .mat file. Here are a few options:
- Use the load function with the '-mat' option to load the entire .mat file into memory. This can be faster than using h5read for small files, but for larger files it may still be too slow.
- Convert the table to a struct using the table2struct function before saving it to the .mat file. This will allow you to use h5read or other functions to read the variables more easily.
- Split the data into smaller .mat files based on your analysis needs, rather than saving everything in one large file. This can improve read and write times.
- Use a different file format that is better suited for large data, such as HDF5 or Parquet.
Ultimately, the best solution will depend on the size and complexity of your data, as well as your specific analysis needs.
댓글 수: 3
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!