Hi Luca,
To handle your matrix and create a datastore, you have a couple of options. You can either convert your matrix to a table and save it as a '.csv' file or use the 'fileDatastore' function to directly work with '.mat' files. Here's how you can achieve this:
1] Using CSV and datastore:
MATLAB's 'datastore' is typically used for tabular data or text files, and not directly for matrices in '.mat' files. Thus, one approach is to convert your matrix to a table and save it as a '.csv' file, which is compatible with 'datastore'.
Here's a sample code for this:
% Convert the matrix to a table
matrixTable = array2table(R.Value);
% Save the table as a CSV file
writetable(matrixTable, 'matrixData.csv');
% Create a datastore from the CSV file
ds = datastore('matrixData.csv', 'ReadSize', 50);
2] Using fileDatastore:
If you prefer to work with the '.mat' file directly, you can use the 'fileDatastore' function. This is particularly useful for large datasets that you want to access in chunks.
Here's how you can use it:
% Define a custom read function for the .mat file
readFcn = @(filename) load(filename, 'R');
% Create a fileDatastore for the .mat file
fds = fileDatastore('R.mat', 'ReadFcn', readFcn, 'FileExtensions', '.mat');
% Read the data
data = read(fds);
% Access the matrix
matrixData = data.R.Value;
To read more about this functions please refer to the below MATLAB documentations: