필터 지우기
필터 지우기

Run a code for all excel files in a folder?

조회 수: 7 (최근 30일)
Indra
Indra 2018년 10월 15일
댓글: Bob Thompson 2018년 10월 17일
Hello, I need to run a code (Dataprocess.m) for all excel files in a folder. When I am running dataprocess.m for one file, it's working. How can I run it sequentially for all the excel files?
  댓글 수: 1
Bob Thompson
Bob Thompson 2018년 10월 15일
I would write a for loop to run through a directory.
files = dir(folder,'*.xlsx') % Syntax here is not going to be perfect, but I'm pretty sure dir is the correct command.
for k = 1:length(files)
data_process_code_file_name_var = files(k).name % Not positive files is actually a structure class, you will have to try it
Dataprocess % Execute code
end

댓글을 달려면 로그인하십시오.

답변 (2개)

madhan ravi
madhan ravi 2018년 10월 16일

Indra
Indra 2018년 10월 16일
Thanks Bob, I made a loop as per your suggestion in a script:
files = dir('*.xls') % Syntax here is not going to be perfect, but I'm pretty sure dir is the correct command . for k = 1:length(files ) data_process_code_file_name_var = files(k).name; % Not positive files is actually a structure class, you will have to try it DataProcess % Execute code end
Then I run my Dataprocess.m code as below:
close all; clear all; clc; % [FileName, Pathname] = uigetfile({'*.xls';'*.xlsx'},'select the excel file'); % % % FileName = [Pathname FileName]; %FileName = '1605301321.xls'; FileName = 'data_process_code_file_name_var';
But it's not working
  댓글 수: 3
Indra
Indra 2018년 10월 17일
Undefined variable "files" or class "files".
Error in Untitled (line 3)
Bob Thompson
Bob Thompson 2018년 10월 17일
What is 'files' defining itself as? Does the dir() command come up with anything? Did you change it at all? You are probably going to have to, and I would suggest looking up the documentation on it first to make sure it is being applied correctly (I.e. right location, right options input, etc.).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by