this code is taking a lot of time to run,

조회 수: 3 (최근 30일)
Prajwal Venkatesh
Prajwal Venkatesh 2020년 1월 17일
댓글: Prajwal Venkatesh 2020년 1월 19일
Is there anyway i can write this code efficiently and reduce runtime? I am trying to import data from multiple files in a folder
clc;clear;
testfiledir = 'C:\Users\bidgu\OneDrive\Desktop\manpower';
matfiles = dir(fullfile(testfiledir, '*.xlsm'));
nfiles = length(matfiles);
datafi = cell(nfiles);
for i = 1 :nfiles
% fid = fopen( fullfile(testfiledir, matfiles(i).name) );
datafi{i} = readtable(fullfile(testfiledir, matfiles(i).name));
% fclose(fid);
end
  댓글 수: 6
dpb
dpb 2020년 1월 18일
"I need the data from all those files at a time and to do anaysis on it"
Then go back to the suggestion I made earlier -- and perhaps Walter's could possibly help some -- and read the files as data; put together and then make a table (or not; depending upon the analyses desired, the array form may be more efficient).
As noted also, it's not possible to help much w/o example of the file(s) and some more specific idea of what it is that is the end result desired (beyond reading them all). Attach sample file if expect anybody to be able to do anything other than simply pontificate.
Prajwal Venkatesh
Prajwal Venkatesh 2020년 1월 18일
what command should i use to read it as any other format of data and then to concatenate it?

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

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 1월 18일
If all the files have the same format, I have seen big improvements using detectImportOptions() on the first file re-use those options for all subsequent ones (expecially if the excel files are formatted oddly):
This is a cumbersome solution, but if you really need speed and will re-use a lot, may be worth it to interact directly with the Excel com server object, which in my experience is much faster to read and write data (at least within a single file).

추가 답변 (1개)

Prajwal Venkatesh
Prajwal Venkatesh 2020년 1월 18일
I have a certain set of words stored in my program and I need to check if anyone of those words are in the excel files of my folder.
I currently have 22 excel files in the folder and I need to check in all sheets , all excel files if that word is present.
That is the reason I need to import all files in the folder all together in a single array to access it.
I cannot concatenate because it is huge data.
  댓글 수: 6
Prajwal Venkatesh
Prajwal Venkatesh 2020년 1월 19일
I get this dialog box and when i click ok for 5 to 6 times then i the program runs and i get my results faster.
Now is there anyway i can get rid of this dialog box that pops up?
Thank You
Prajwal Venkatesh
Prajwal Venkatesh 2020년 1월 19일
Resolved the dialog box issue

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by