필터 지우기
필터 지우기

converting cell to str

조회 수: 4 (최근 30일)
Mahesh Vibhute
Mahesh Vibhute 2015년 9월 2일
댓글: Mahesh Vibhute 2015년 9월 3일
Hi.
I am trying to load a bunch of log files, and then find certain keywords in it.
C is the cell containing the 40 input files in which i want to find certain keywords.
iscellstr(C) = 0
Since i cannot use C in strfind, i have to convert it into C2 as:
C2 = [C{:,i}]
However, here's the main problem. C contains all the 40 files i want to read, but C2 contains only one, the 40th file.
Any suggestions about the conversion will be appreciated.
Thanks in advance,
Mahesh

채택된 답변

Greig
Greig 2015년 9월 3일
You don't need to convert to a strings, try using cellfun instead. For example,
C2 = cellfun(@(x) strfind(x, 'MyPattern'), C, 'UniformOutput', 0);
This returns a cell that contains the indices for each element of C where "MyPattern' is found. Many may be empty, so this is why UniformOutput is specified as zero (i.e., non-uniform output).
You may need to use something like
cellfun(@isempty, C2)
and cell2mat in the final processing steps, depending on what you are want to do after.
  댓글 수: 1
Mahesh Vibhute
Mahesh Vibhute 2015년 9월 3일
That worked! Thanks a lot!!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by