Clear Filters
Clear Filters

Create for loop to read in multiple excel files

1 view (last 30 days)
OliK
OliK on 8 Oct 2015
Answered: dpb on 8 Oct 2015
Have this as my code so far:
%%Clear the workspace
clc;
clear all;
close all;
%%Import Data
imp = xlsread('HiG_67.csv','J:J'); %Import 'x ACC' Data
FilterValue=30; %Filter values less than 30
imp(imp<FilterValue)=0; %Set values less than 30 to 0
time= xlsread('HiG_67.csv','C:C')'; %Create time variable
%%Plot data and Calculate mean/SD
plot(time,imp) %Plot time against filtered data
n=sum(imp~=0); %Calculate mean of filtered data
n(n==0) = NaN;
m = sum(imp) ./ n;
sd=sqrt(sum(imp.^2)./sum(imp~=0) - m.^2); %Calculate Standard Deviation
%%Output data into Excel file
filename = 'Filter_67.csv';
xlswrite(filename,imp);
Now I would like to create a loop to read in 28 .csv files from the same folder, they are all titled 'HiG_**.csv' ( being 67-94). If I could then filter them all then output them as 'Filter_**.csv'
Thanks

Answers (1)

dpb
dpb on 8 Oct 2015
See the FAQ How can I process a sequence of files? I'll note I'm particularly fond of the dir solution for processing the input files in cases such as you've outlined.

Categories

Find more on Data Import from MATLAB 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!