필터 지우기
필터 지우기

How do I extract a row of data from a cell array based on a string?

조회 수: 2 (최근 30일)
Dave
Dave 2015년 3월 25일
답변: Dave 2015년 3월 26일
I know there are similar questions like that and have reviewed most, but don't quite have it figured out yet. As an example I have a file containing information similar to below: 07/03/2010 07:15 AM 'Run' 'Race' 4 'Mile' 10/24/2010 12:00 PM 'Run' 'Hill' 4 'Mile' 11/14/2010 09:30 AM 'Run' 'Easy' 4 'Mile' I would like to extract all those rows that say are of type 'Hill'.
I've tried the following: hill_log = runlog1(cat(1,runlog1{:,4}) == 'Hill',:)
but get: Undefined function 'eq' for input arguments of type 'cell'. No doubt some basic nuance I'm missing.
Thanks

채택된 답변

Sean de Wolski
Sean de Wolski 2015년 3월 25일
cat(1,runlog1{:,4})
This is a cell so you can't compare it to a string. Instead use strcmp which works on cells and strings in this manner. Something like:
strcmp(cat(1,runlog1{:,4}),'Hill')

추가 답변 (1개)

Dave
Dave 2015년 3월 26일
Still working on this a bit. I've tried the following and just get the 1st row with 'Hill'. hill_log = strcmp(runlog1{:,4}, 'Hill'); for i=1:length(hill_log); j=0; if hill_log(i)==1 j=j+1; hill_log_matrix(j,:) = runlog1(i,:) ; end end
I'm not a coder by trade, obviously, so any further hints would be appreciated.
TIA

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by