Use of a loop to read and concat multiple cell table

1 view (last 30 days)
Anirudh Peralai Ravisundar
Edited: VBBV on 23 Sep 2021
Hello,
I have a 24x1 cell named 'results'. Each cell consists of 36977x16 double table. I want to read a particular column, say column number 12, in each of these 24 cells and return the maximum value in that column matrix. Here I have created a 24x1 cell named 'results' by reading 24 .csv files. I was trying to use a 'for' loop but did see any success.
files = dir('*.csv');
num_files = length(files);
results = cell(length(files), 1);
for i = 1:num_files
results{i} = xlsread(files(i).name);
end

Answers (2)

VBBV
VBBV on 23 Sep 2021
Edited: VBBV on 23 Sep 2021
%if true
results{i} = readmatrix('files(i).name');
Use readmatrix instead or try
%if true
results{i} = xlsread('files(i).name');
  1 Comment
VBBV
VBBV on 23 Sep 2021
You could also try to use options to import data from specific sheet and range if cells from file.

Sign in to comment.


Anirudh Peralai Ravisundar
My questions relates to extracting data from the 12th column of results{i}. Essentially, results{i} is a 24x1 cell where a table of 36977x16 double constitutes each cells.
  1 Comment
VBBV
VBBV on 23 Sep 2021
results{i} = xlsread(files(i).name);
K{i} = results{i}(:,12);
Add this line in loop. K is the array with data extracted from 12th col of each of cell arrays.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!