필터 지우기
필터 지우기

How to extract some columns from txt file to cell

조회 수: 3 (최근 30일)
Jiajie Zhang
Jiajie Zhang 2019년 6월 11일
편집: Prasanth Sikakollu 2019년 6월 12일
I have a txt file as follows
The intersection size between 1_1.txt and 1_2.txt is 7
The intersection size between 1_1.txt and 1_3.txt is 4
The intersection size between 1_1.txt and 1_4.txt is 7
The intersection size between 1_1.txt and 1_5.txt is 2
The intersection size between 1_1.txt and 1_6.txt is 7
how to transfer this file to cell?
I want a cell like this, which has three columns,
1_1.txt 1_2.txt 7
Thank you.

답변 (1개)

Prasanth Sikakollu
Prasanth Sikakollu 2019년 6월 12일
편집: Prasanth Sikakollu 2019년 6월 12일
Assume that the above text is in 'sample.txt'.
Read data from sample.txt to a table using readtable() function.
Extract the required columns from the table.
Convert the table into cell array.
The following code does that.
table = readtable('sample.txt');
table = table(:,[5,7,9]);
result = table2cell(table);
Hope this helps in solving your problem.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by