필터 지우기
필터 지우기

load files containing part of a string in the file name and the load that file

조회 수: 5 (최근 30일)
Lu
Lu 2011년 3월 26일
Hi everyone!
Im kind of new to matlab and I have the following problem: I have many files as .mat files with the following names, all in one folder. So what I want to do is to load all BASF files first and save them into a new BASF folder and then load all BIOG files and save them into a new BIOG folder.
data20091019_1BASF.DE
data20091020_1BASF.DE
data20091021_1BASF.DE
data20091020_1BIOG.DE
data20091022_1BIOG.DE
data20091101_1BIOG.DE
So far, this is what I have tried :
clear all
dirData=dir('*.mat');
filenames={dirData.name};
stringi=filenames;
for k=1:length(dirData)
stringi=filenames;
basf=regexp(stringi,'^dataOut(\d+)_1BASF.DE_rek.mat$','match');
basf(cellfun(@(basf) isempty(basf),basf))=[]; %get rid of empty cell arrays
biog=regexp(stringi,'^dataOut(\d+)_1BIOG_p.DE_rek.mat$','match');
biog(cellfun(@(biog) isempty(biog),biog))=[];
load(basf)
end
The problem is when I try to load all the files included in the basf cell array it says " Argument must contain a string". So I dont know how to make matlab load all the files that contain BASF or BIOG in ther file names. Could you please help me? Thank you so much! Lourdes
  댓글 수: 2
Jan
Jan 2011년 3월 26일
BTW: basf(cellfun(@(basf) isempty(basf),basf))=[]
Faster: basf(cellfun('isempty', basf))=[]
Lu
Lu 2011년 3월 27일
Thank you Jan for the answer!
It does make it faster! but do you have some ideas on how to make matlab load the files I need? like load just the basf files and then load just biog files?
thank you,
lourdes

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

답변 (2개)

Paulo Silva
Paulo Silva 2011년 3월 26일
try with this litle change:
load(char(basf))
or this one:
load(basf{:})
  댓글 수: 1
Lu
Lu 2011년 3월 27일
Hi Paulo,
Thank you for your answer! I tried both
load(char(basf)) and it gives me the following error message :??? Error using ==> char
Cell elements must be character arrays.
when I try load(basf{:}) it gives me the following error message: ??? Error using ==> load
Argument must contain a string.
I dont have any other ideas on how to make matlab load the files using the filenames contained in the cell arrays of basf and biog. Do you have other ideas? I would really appreciate your help :)
thank you
lourdes

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


Walter Roberson
Walter Roberson 2011년 3월 27일
You cannot load more than one file in a single command. Please see the FAQ on handling multiple files.

카테고리

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