Clear Filters
Clear Filters

Error reading the files in ensemblefilestorage

1 view (last 30 days)
I have created an ensemble storage of multiple csv files but in the end it shows an error that it cannot read the ensemble as the data is not in .MAT format. how to fix this?

Answers (1)

Dinesh
Dinesh on 9 Mar 2023
Hi Sahil.
Currently your data is in CSV format, but it expects the ensemble storage data to be in ".mat" format.
To use an ensemble of CSV files as input to for example a Simulink model, you will need to first load the data from each CSV file into MATLAB using the "readtable" function, then combine the data sets into a single cell array and save it into a ".mat" file.
Here's an example code to do this:
% Define the file names and paths for all the ".csv" files
file_names = {'data1.csv', 'data2.csv', 'data3.csv'};
file_paths = {'path/to/data1', 'path/to/data2', 'path/to/data3'};
% Initialize a cell array to store the data.The length of it is no of files
data_cell = cell(length(file_names), 1);
% Load the data from each CSV file into the cell array
for i = 1 : length(file_names)
file_path = fullfile(file_paths{i}, file_names{i}); % concatenating folder and file name
data_cell{i} = readtable(file_path); % reading each CSV table and storing it in the cell array
end
% Combine the data sets into a single cell array
data = vertcat(data_cell{:});
% each element in "data_cell" is a table, but "data" is a single table that
% contains all the data from all the CSV files concatenated together.
% Save the data into a ".mat" file
save('data.mat', 'data');
Now this ensemble can be used as an input to for example a Simulink model without any problem.

Categories

Find more on Predictive Maintenance Toolbox in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!