fscanf read a specific line
Afficher commentaires plus anciens

Hello, in matlab 1-2-3... I have prepared 10 files of 100 numbers, each containing 10 numbers. Now, what I want to do is the 1st line from the 1st file, the 2nd line from the 2nd file, that is n. from file n. I want to get the row. Can you help with the code?
Réponses (1)
Here's an example using three files:
n_files = numel(dir('ders*.txt')); % store the number .txt files whose names start with "ders" in the working directory (in this case, 3)
result = zeros(1,n_files); % initialize the resulting row vector
for ii = 1:n_files
dosya = fopen("ders"+ii+".txt","r");
temp = fscanf(dosya,"%d",Inf); % store all numbers from the ii-th file in the temporary variable "temp"
result(ii) = temp(ii); % store the ii-th number in "temp" as the ii-th element of the result vector
fclose(dosya);
end
disp(result);
Catégories
En savoir plus sur Whos dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

