Reading from a .txt file

조회 수: 2 (최근 30일)
Peter
Peter 2014년 7월 28일
편집: Cedric 2014년 7월 28일
Hello,
I have a .txt file with 100 matrices (3*4) each followed by a number. I want to read matrices into a 3D array and numbers into 1D array? How do I do it?
Data looks like:
1 2 3 4
1 2 3 4
1 2 3 4
5
4 5 6 7
4 5 6 7
4 5 6 7
7
3 5 7 3
3 5 7 3
3 5 7 3
3 5 7 3
3
...

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 28일
d=importdata('file.txt');
A=d;
b=A(4:4:end,1);
A(4:4:end,:)=[];
A=reshape(A,3,4,[]);
disp(b)
disp(A)
  댓글 수: 1
Cedric
Cedric 2014년 7월 28일
편집: Cedric 2014년 7월 28일
+1 Damn' ;-), I'll have to start using this IMPORTDATA!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by