handling data inside for loop
Show older comments
Hi, I am trying to read information from several .csv files located inside a folder.
As those files are read by Matlab, I need to add a line after the data for each .csv file so I can distinguish what data is from which file.
I need to turn that data into a table to be able to process it after.
I'm getting stuck in the line where it is storing the data in cell array:
%TS_R_SS
folderPath4 = '03TS-all_time_domain\Relaxing\SS';
% Get a list of all CSV files in the folder
filePattern4 = fullfile(folderPath4, '*.csv');
csvFiles4 = dir(filePattern4);
% Initialize a cell array to hold the data from each file
dataAllFiles4 = cell(length(csvFiles4)*2, 1);% Extra space for empty lines
% Loop through each file and read the data
dataIndex = 1
for k4 = 1:length(csvFiles4)
% Get the full file name
baseFileName4 = csvFiles4(k4).name;
fullFileName4 = fullfile(folderPath4, baseFileName4);
% Read the data from the CSV file
dados4 = readtable(fullFileName4);
% Store the data in the cell array
dataAllFiles4(dataIndex:dataIndex + height(dados4) - 1) = table2cell(dados4);
% Update the index for the next data entry
dataIndex = dataIndex + height(dados4);
% Add an empty line after each file's data
dataAllFiles4{dataIndex} = []; % Insert an empty cell
dataIndex = dataIndex + 1; % Move to the next index
end
The error message it shows is:
Unable to perform assignment because the left and right sides have a
different number of elements.
Error in Extract_audio_features_Neurokit (line 165)
dataAllFiles4(dataIndex:dataIndex + height(dados4) - 1) =
table2cell(dados4);
How can I solve this please?
Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!