필터 지우기
필터 지우기

Read two lines from a file and repeat for next lines

조회 수: 2 (최근 30일)
bbah
bbah 2020년 12월 3일
댓글: Ameer Hamza 2020년 12월 3일
Hello everybody
i have a file part like this:
1, 695, 400, 8, 519, 2721, 2426, 2034, 2545, 6082, 6081, 6080, 6079, 6083, 6084, 6085,
6086, 6088, 6087, 6089, 6090
2, 694, 117, 678, 730, 2720, 2143, 2704, 2756, 6094, 6093, 6092, 6091, 6095, 6096, 6097,
6098, 6100, 6099, 6101, 6102
3, 116, 679, 726, 724, 2142, 2705, 2752, 2750, 6106, 6105, 6104, 6103, 6107, 6108, 6109,
6110, 6112, 6111, 6113, 6114
4, 724, 722, 683, 116, 2750, 2748, 2709, 2142, 6117, 6116, 6115, 6103, 6118, 6119, 6120,
6110, 6114, 6121, 6122, 6112
5, 115, 728, 692, 682, 2141, 2754, 2718, 2708, 6126, 6125, 6124, 6123, 6127, 6128, 6129,
6130, 6132, 6131, 6133, 6134
Now i would like to read the first two lines and add to a cell like:
for b=(start_elements(i)+1):(end_elements(i)-1)
Element{i}(p,:)=strread(FFLINES{b}, '%f', 'delimiter', ',');
p=p+1;
end
In the end i will have a cell Element{1,1} with all the 21 elements but i cannot figure out how to do it.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 3일
편집: Ameer Hamza 2020년 12월 3일
It is more efficient to read everything in a single call. I/O operations on disk can be a bottleneck, so that should be reduced as much as possible
str = fileread('data.txt');
data = textscan(str, '%f', 'Delimiter', ',');
data = reshape(data{1}, 21, []).'
data.txt is attached.
  댓글 수: 2
bbah
bbah 2020년 12월 3일
thank you a lot
Ameer Hamza
Ameer Hamza 2020년 12월 3일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by