Discussion:
Need help parsing a cell array containing text
(too old to reply)
Uwe Kotyczka
2018-03-08 16:59:15 UTC
Permalink
Raw Message
Hi,

[Using Matlab2015aSP1]

I have a cell array, say textCells, where each cell contains
a string of the form "keyword = value". For example let

textCells{1,1} = "Gauss_order = 1.1"
textcells{2,1} = "min_Gauss_order = 1.0"
textcells{3,1} = "max_Gauss_order = 2.0"

To parse textCells for a couple of keywords I have search string:

strSearch = 'Gauss_order';

I used the function strfind to find

IndexC = strfind(textCells, strSearch);
Index = find(not(cellfun('isempty', IndexC)));

Works fine for the search string 'min_Gauss_order'.
However for the search string 'Gauss_order' I get three indicees
1,2,3 since each cell contains 'Gauss_order' as a substring.
IndexC has the values

IndexC{1,1} = [ 1]
IndexC{2,1} = [ 5]
IndexC{3,1} = [ 5]

So my idea is to check IndexC for cells containing [ 1] to get only
those cells which start with 'Gauss_order'.
But I can't figure out the correct syntax how to use cellfun for
such a check.

If someone could please give me a hint.
dpb
2018-03-09 05:17:26 UTC
Permalink
Raw Message
find(cell2mat(strfind(textcells,'Gauss_order'))==1)
ans =
1
--

Loading...