Importing data from different excel sheets and many excel files (csv files)

21 ビュー (過去 30 日間)
Coco
Coco 2019 年 1 月 3 日
コメント済み: Luna 2019 年 1 月 4 日
Hi everyone, I am looking for a help:) I obtained data from Imaris analysis and now I've got around 70 excel files. Each contain many sheets (which contain a values for different parameter). I want to create variables for each parameter and combine values from this 70 excel files. Subsequently I want to do some calculations (mean value etc)
I ve got something like this:
clear all
close all
matfiles = dir('blablabla\*.csv');
% And here should be something for excel sheet:)
branches = []
junctions =[]
for i=1:length(matfiles)
Z = csvread(sprintf('%i.csv',(i)),1,1);
branches = Z(:,1);
junctions = Z(:,2);
mean_branches (i) = sum(branches);
mean_junctions (i) = sum(junctions);
end
Thank you in advance:)

採用された回答

Luna
Luna 2019 年 1 月 3 日
編集済み: madhan ravi 2019 年 1 月 4 日
Hi CoCo,
You can try this below. I made some comments also.
fPath = 'C:\Users\...\Desktop\excelsFolder'; % filepath of your excel or csv files
cd(fPath) % you don't need to change directory you can use dir with filepath also.
fNames = dir('*.xlsx'); % I used 4 excels named: excel1.xlsx,excel2.xlsx,excel3.xlsx,excel4.xlsx ...
fileNamesArray = cell(1,numel(fNames)); % get the excel file names
j = 1; % define another counter for inner for loop.
for i = 1:numel(fNames)
fileNamesArray{i} = fNames(i).name; % gets the file names in the directory you can also work another directory too.
[excelStatus,excelSheets] = xlsfinfo(fNames(i).name); % gives you the sheet list (not sure if it works with csv files also)
for k = 1:numel(excelSheets) % loop for each sheet in excel
[num,txt,raw] = xlsread(fNames(i).name,excelSheets{k}); % reads the k.th sheet and gets data into raw. you can also use csvread function which reads only numeric values.
% get what you need from here from the num or raw value store it inside
% any other array and continue your life like below.
myStoredData{j,1} = raw(:,1); % store your i.th excel's k.th sheet data in myStoredData cell array. Or you can use numeric array
j = j+1;
end
end
  2 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 4 日
Coco's answer moved here for consistency:
Thank you so much Luna :)
It is working :)
Luna
Luna 2019 年 1 月 4 日
Your welcome :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by