필터 지우기
필터 지우기

find char indices (row,column)

조회 수: 6 (최근 30일)
Juan Rosado
Juan Rosado 2012년 7월 12일
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?

채택된 답변

Jan
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
Juan Rosado
Juan Rosado 2012년 7월 13일
Jan, thank you for your answer.
The thing is I am converting the text to character array because I want to display a specified data following the '<B>' tag
For example,
<FONT SIZE=+1 COLOR="#800000">TONIGHT</FONT>'
'EAST WINDS 11 TO 16 KNOTS. SEAS 2 TO 4 FEET. SCATTERED'
'SHOWERS.
I want MATLAB to display,
winds: 'EAST WINDS 11 TO 16 KNOT'
waves: 'SEAS 2 TO 4 FEET'
% divide the sentence in phrases using structured variables
and for this I need to generate a character array because a string would output the whole sentence which I dont want.
What do you suggest me?
F.
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 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