I am searching for an appropriate data structure to save my results in. After analysis of my files (>1000), results metadata for each file should be saved into a single structure / table / db, that allows for subsequent analysis of the results based on metadata (i.e. compare different groups). The results per file comprise several single values & a vector (resultType). The metadata per file comprise 4 features. As I wrote, the idea is to compare result-values based on certain metadata features.
Current approach: save to struct:
results=struct
% metadata
results.metadata=struct
results.metadata.metaval1='val'
% results-values
results.results=struct
results.results.resultsType1=val
filter results corresponding to certain metadata-group features ('val1'-'val4') to obtain the values for resultsType1:
idx = strcmp('val1',{results.metadata.metaval1}) & ...
strcmp('val2',{results.metadata.metaval2}) & ...
strcmp('val3',{results.metadata.metaval3}) & ...
strcmp('val4',{results.metadata.metaval4}) ;
group1_resultType1 = results(idx).resultType1;
I was wondering, whether there might be a better/easier approach using maybe a sqlit3-database or simply a table to get result-values for chose metadata-features?
CodePudding user response:
For this, I'd recommend MATLAB Tables. You can structure your data to be read into a table(s) which look like:
T =
3×4 table
Files Results Metadata_Date Metadata_Bool
_____ ________________________ _____________ _____________
{'A'} {[1 2 3 4 5 6 7 8 9 10]} 08-Dec-2022 true
{'B'} {[1 2 3 4 5 6 7 8 9 10]} 07-Dec-2022 false
{'C'} {[1 2 3 4 5 6 7 8 9 10]} 09-Dec-2022 true
You can then access the data by querying the table on row, column, or some combination of the two:
% Get entries that were uploaded before today
>> T(T.Metadata_Date < datetime('Today'),:)
ans =
1×4 table
Files Results Metadata_Date Metadata_Bool
_____ ________________________ _____________ _____________
{'B'} {[1 2 3 4 5 6 7 8 9 10]} 07-Dec-2022 false
If you store data in multiple tables, you can perform joins and set operations like you can in SQL.