converting cell to str

3 vues (au cours des 30 derniers jours)
Mahesh Vibhute
Mahesh Vibhute le 2 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

Réponse acceptée

Greig
Greig le 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.
  1 commentaire
Mahesh Vibhute
Mahesh Vibhute le 3 Sep 2015
That worked! Thanks a lot!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by