Effacer les filtres
Effacer les filtres

Matlab file names in a loop

5 vues (au cours des 30 derniers jours)
Avik Mahata
Avik Mahata le 18 Juil 2022
Commenté : Avik Mahata le 18 Juil 2022
I have a set of files named, dipoles.0.5000.xvg , dipoles.5000.01.10000.xvg and so on. I need to read those files and save in a different data(k) matrix. In the below form I am getting an Invalid file identifier error.
clc
clear all
for i = [0 5000.01 10000.01 15000.01 20000.01 25000.01 30000.01 35000.01 40000.01 45000.01 50000.01 55000.01 60000.01 65000.01 70000.01 75000.01 80000.01 85000.01 90000.01 95000.01];
for j = 5000:5000:100000
for k = 1:1:20
Data(k) = import_xvg('dipoles.%i.%j.xvg');
end
end
end

Réponses (1)

Chunru
Chunru le 18 Juil 2022
Modifié(e) : Chunru le 18 Juil 2022
fn = dir("dipoles*.*");
for i = 1:length(fn)
x{i} = readmatrix(fn(i).name, "NumHeaderLines", 27);
end
x
x = 1×2 cell array
{12×5 double} {18×5 double}
  5 commentaires
Chunru
Chunru le 18 Juil 2022
See above.
Avik Mahata
Avik Mahata le 18 Juil 2022
Thanks. It works.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices 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