fscanf read a specific line

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?

댓글 수: 2

Voss
Voss 2023년 1월 1일
"Answer" from yusuf moved here (couldn't use the Move function for some reason):
Voss
Voss 2023년 1월 1일
Comment on "Answer" from yusuf moved here (could use the Move function, but then they'd be out of order):

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

답변 (1개)

Voss
Voss 2023년 1월 1일

0 개 추천

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);
1 12 23

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

릴리스

R2022b

태그

질문:

2022년 12월 30일

댓글:

2023년 1월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by