Hi all, i've a problem here when checking for the regular expression of strings in a cell.
Let
x = {'width = "13" height = "2"'
'width = "12" height = "90"'
'width = "2" height="5"'
'width = "0" height="5"'
'width = "20" height="5"'
'width = "1" height="0"'
'width = "20" height="50"'};
I use this two statement to find the width and height which smaller than 10.
width = find(~cellfun('isempty',regexp(html_only, 'width\s?=\s?"\s?[0-9]\s?"', 'match')));
height = find(~cellfun('isempty',regexp(html_only, 'height\s?=\s?"\s?[0-9]\s?"', 'match')));
How to make it to check for either width or height is smaller than 10. I code like this, but it cant work, and error prompted out.
width = find(~cellfun('isempty',regexp(html_only, 'width\s?=\s?"\s?[0-9]\s?"' | 'height\s? =\s?"\s?[0-9]\s?"', 'match')));

답변 (1개)

Jos (10584)
Jos (10584) 2014년 4월 10일

0 개 추천

Again , approach this in two steps. First extract the numbers and then apply the condition.
As you have found out, it is much harder to code this in a single obfuscated line ...

댓글 수: 2

Jacky
Jacky 2014년 4월 10일
편집: Jacky 2014년 4월 10일
Thanks for your reply, i able to make it in one statement
find(~cellfun('isempty',regexp(x, 'width\s?=\s?"\s?[0-9]\s?"', 'match') | regexp(x, 'height\s?=\s?"\s?[0-9]\s?"', 'match')));
and in several lines also
w1 = regexp(x, 'width\s?=\s?"\s?[0-9]\s?"', 'match');
h1 = regexp(x, 'height\s?=\s?"\s?[0-9]\s?"', 'match');
find(~cellfun('isempty', w1) | ~cellfun('isempty', h1));
Which one is more preferable?
Jos (10584)
Jos (10584) 2014년 4월 10일
Which code is easier to understand?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2014년 4월 10일

댓글:

2014년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by