Effacer les filtres
Effacer les filtres

How to load files using a for loop or automated process

12 vues (au cours des 30 derniers jours)
Arsal15
Arsal15 le 22 Fév 2016
Commenté : Arsal15 le 22 Fév 2016
I want to load files every time for a simulation purpose. I want to change 1 at the end of file name "Data_1500_1" using a loop or any logic that it can load all files by it self. Like I am doing here. Next time i want to load file named as "Data_1500_2" with 2 at the end and then 3,4,5,6... and so on.
if true
A = load('Data_1500_1.mat');
B = load('Data_2000_1.mat');
C = load('Data_3000_1.mat');
D = load('Data_4000_1.mat');
E = load('Data_5000_1.mat');
F = load('Data_6000_1.mat');
G = load('Data_7000_1.mat');
H = load('Data_8000_1.mat');
I = load('Data_9000_1.mat');
J = load('Data_10000_1.mat');
end
Need your guidance.
  2 commentaires
jgg
jgg le 22 Fév 2016
Modifié(e) : jgg le 22 Fév 2016
Why is that a desirable feature? Do you need all of the history of the data saved as different .mat files. Wouldn't it be similar to save a variable to the same .mat file each time which told you which run.
Like, suppose you're outputting data to each matrix. Why not, instead of saving it as a new file, just append this struct:
data_struct = struct('data',data, 'run_id', run_id)
save('Data_1500.mat', 'data_struct','-append')
Where run_id is the run you're doing? This would be much simpler and less prone to error. Plus, you wouldn't generate bazillions of little files which is really, really bad for most systems.
Arsal15
Arsal15 le 22 Fév 2016
Well I have data of each run with same variables but different values inside each of them in all files. That's why i need to load a set of files and plot their data.
Thanks alot jgg...U have given a new idea to append structure. Let me try it.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 22 Fév 2016
  1 commentaire
Arsal15
Arsal15 le 22 Fév 2016
Jan Simon, Thanks for this useful link.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Sequence and Numeric Feature Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by