converting cell to str

7 views (last 30 days)
Mahesh Vibhute
Mahesh Vibhute on 2 Sep 2015
Commented: Mahesh Vibhute on 3 Sep 2015
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

Accepted Answer

Greig
Greig on 3 Sep 2015
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.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!