How to loop through a folder of ifiles in Matlab

5 views (last 30 days)
Hello all,
I have a lack of efficiency of my script that it could be sort out whether I were able to loop through a folder where I have all my files.
The script is working fine the only thing is that I have to go file by file loading them. I have searched for information of how to do it and most of it explain how to get txt. .cvs. jpg and so on. However, I have a bunch of Ifiles coming from AVL combustion system, which I am not sure how to load them one by one in a loop.
The idea it would to run a loop where you can load each ifile in a function to extract all the variables only selecting the folder. I have managed to have everything working but I am stack in that step. In this way, I could leave the script overnight working rather than the need to go one by one.
Any help it would be more than welcome.
Thank you very much.
Cruz

Accepted Answer

TADA
TADA on 19 Dec 2018
Edited: TADA on 19 Dec 2018
I Have No Idea What Is This ifile format. But This File Exchange Seems Exactly Like What You're Looking For:
  3 Comments
TADA
TADA on 19 Dec 2018
Ok, so you only need to iterate through your files?
I think this should do the it:
path = pwd; % set your folder path here
filePattern = '*.ifile'; % or whatever file extension these files are saved as
files = dir([path '\' filePattern]);
fileNames = strcat({files.folder}, '\', {files.name});
% I think that load_ifile returns a struct?
% If you know in advance what fields it has, and all structs have the same
% fields, you can use a struct array instead of a cell array
data = cell(1, length(files));
for i = 1:length(files)
data{i} = load_ifile(fileNames{i});
end
Santos Romero
Santos Romero on 19 Dec 2018
Hi,
yes, I just need to iterate through the files and you are correct, it is a struct and it a good point about to use struct array instead of cell array.I will try what you suggested me tomorrow at work and let you know!!!
thanks for your help.
best regards!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!