Extract specific column information from table

조회 수: 1 (최근 30일)
Francisco
Francisco 2016년 3월 22일
댓글: Francisco 2016년 3월 22일
Hi all, Maybe you could help me with the following?
I have several *.txt files with 3 columns information, here just an example of one file:
namecolumn1 namecolumn2 namecolumn3
-----------------------------------------------------------
name1.jpg someinfo1 name
name2.jpg someinfo2 name
name3.jpg someinfo3 name
othername1.bmp info1 othername
othername2.bmp info2 othername
othername3.bmp info3 othername
I would like to extract from "namecolumn1" only the names starting with name but from column 1.
My code look like this:
file1 = fopen('test.txt','rb');
c = textscan(file1,'%s %s %s','Headerlines',2);
tf = strcmp(c{3}, 'name');
info = c{1}{tf};
the problem is that when I do disp(info) I got only the first entry from the table: name1.jpg and I would like to have all of them:
name1.jpg
name2.jpg
name3.jpg
Thanks a lot in advance!

채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 22일
info{1}(tf)
Note: you are using what MATLAB calls a cell array. In MATLAB a table is a different data structure.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by