How to import a text file into matlab

조회 수: 1 (최근 30일)
mohamed Faraj
mohamed Faraj 2018년 10월 7일
댓글: jonas 2018년 10월 8일
I have a text file "attached" and I would like to import it to matlab. The file ia arranged into 3 columns and each of three columns has 4 sub-columns. I want to import these data to an array M with size(M)=[80,3,4], e.g., if the first row of the text file is {1,2,3,4} {5,6,7,8} {9,10,11,12}, then M(1,1:3,1)={1,5,9},M(1,1:3,2)={2,6,10}...etc

채택된 답변

jonas
jonas 2018년 10월 7일
편집: jonas 2018년 10월 7일
fid = fopen('t.txt');
out=textscan(fid,repmat('%f',[1,12]),'delimiter',{'\t',',','{','}'},'MultipleDelimsAsOne',1)
fclose(fid)
out=cell2mat(out);
out=reshape(out,[80,4,3])
or perhaps you need to add this line to get the right structure
out = permute(out,[1 3 2]);
  댓글 수: 2
mohamed Faraj
mohamed Faraj 2018년 10월 8일
Thank you Jonas. It worked well
jonas
jonas 2018년 10월 8일
My pleasure! Please formally accept the answer!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by