Effacer les filtres
Effacer les filtres

I use matlab. I load a data(.dat) file and run my program on it and get results. I have 900 such data files and want to write a loop such that at the end I get results corresponding to all data files at once. Is there a way to do it?

8 vues (au cours des 30 derniers jours)
Loading all the data files each at once and getting results corresponding to it is a time taking process and it needs lot of effort. So I want to use a loop for i=1:900 and write my program. for i=1 it should load 1st data(.dat) file and give me results after completing on this file,for i=2 it should load another data(.dat) file. It should carry on up to i=900. Is there a possibility? Also tell me a way to save workspace after every iteration. I have to get 900 work space files.
  1 commentaire
RAJ KUMAR
RAJ KUMAR le 4 Avr 2017
Modifié(e) : RAJ KUMAR le 4 Avr 2017
%Name the files as filename1.dat, filename2.dat,...etc.
%then run the following code.
numfile=900;
for i =1:numfile
argstr1=['load(filename' , int2str(i) , '.dat);'];
eval(argstr1);
end
end

Connectez-vous pour commenter.

Réponse acceptée

David Sanchez
David Sanchez le 5 Juin 2013
To save workspace variables, use the command save. see "help save" for the details. To load the files in a loop, use a cell array to store the information of each file.
my_data = cell(900,1); % initialize the cell array
my_files = dir('*.dat'); % structure containing your *.dat files
for k=1:900
my_data{k} = load(my_files(k).name); % load .dat file recursively
end

Plus de réponses (1)

Rongzhi Wei
Rongzhi Wei le 23 Sep 2019
I have a problem of how to load a .dat file into matlab and run it by an external program, which has been solved by you.
the external program is a black box, a function simulator. I need to load the data file (.dat file) and run it by funcao.exe.
I only know use
system ('funcao.exe')
to call that program, but how to load that .dat file , and make this external program accept the data.
thank you!

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by