find char indices (row,column)
8 ビュー (過去 30 日間)
古いコメントを表示
Grettings,
I have this html text file which I convert into a character array (38x343 char) using 'char' and I am triying to find the indices of all the lines starting with '<B>' using the command 'find'
So far I have typed this code,
[row,col]=find(strncmpi('outchar', '<B>', 3)) % outchar = variable of char array
but I keep getting empty brackets:
row =
[]
col =
[]
One line of the text file looks like this:
<B><FONT SIZE=+1 COLOR="#483D8B">COASTAL WATERS FORECAST
And I want MATLAB to output
row [3 4 5 6 ...] col [1:3 ....] % 1:3 = columns from 1 to 3
What can I type?
0 件のコメント
採用された回答
Jan
2012 年 7 月 13 日
編集済み: Walter Roberson
2012 年 7 月 13 日
Variables are not enclosed in quotes:
[row,col] = find(strncmpi(outchar, '<B>', 3))
In opposite to this strncmpi('outchar', '<B>', 3) searches in the string 'outchar', which does not start with '<B>'.
I assume a cell string would be more convenient and efficient than a CHAR matrix.
STRNCMPI replies a logical vector: TRUE if the string matchs, FALSE otherwise. Therefore FIND will give you the wanted row indices, but not the columns "[1:3, ...]".
2 件のコメント
F.
2012 年 7 月 13 日
I think you should use a cell array like Jan Simon.
After you have the command regexp to give you the position of the first character of your string. With the length, you’ll have your columns.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!