How can I read text file data separately row by row into different array
조회 수: 18 (최근 30일)
이전 댓글 표시
Hi, everyone. If the text tile data is shown as below:
13,7,8,4,9
3,21,5,3,7
4,6,87,35,7
45,2,5
I would like to read the text file into different array like a=[13 7 8 4 9], b=[3 21 5 3 7;4 6 87 35 7] and c=[45 2 5]. Is there any code to solve this problem? Thank you for reading my question.
댓글 수: 0
답변 (1개)
Srivardhan Gadila
2020년 4월 11일
편집: Srivardhan Gadila
2020년 4월 11일
The following code might help you:
filename = 'textFile.txt';
delimiterIn = '\n';
Data = importdata(filename,delimiterIn);
a = str2num(Data{1})
b = [str2num(Data{2});str2num(Data{3})]
c = str2num(Data{4})
Or
filename = 'textFile.txt';
delimiterIn = ',';
Data = importdata(filename,delimiterIn);
a = Data(1,:)
b = Data(2:3,:)
c = Data(4,:)
c = c(~isnan(c))
The textFile.txt has the following data:
13,7,8,4,9
3,21,5,3,7
4,6,87,35,7
45,2,5
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!