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