matching strings in a matrix of m x n and then sorting

Hey all,
this is my first post at the forum. kindly ignore the mistakes if any.
i have been finding a way to match few keywords or strings in a matrix and if that keyword is matched the whole row , i.e all the field values in that row of matrix will be separated out to a new matrix. and all those similar rows which satisfy the keywords wil make a new matrix. kidnly note that strings can be more than one .
for e.g
i have to separate out all the packets with the term 'facebook' in them and i have the matrix like
no field1 field2
1 www.facebook.com user1
2 www.gmail.com user2
3 www.kasperksy.com user2
4 www.google.com user4
and if i want to sort out all the rows (into a new matrix) in which 'facebook' and 'gmail' occur , what do i need to do . please guide me along , i dont ask for the full code just help me out how to start with.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 4월 5일
K = {1 'www.facebook.com' 'user1'
2 'www.gmail.com' 'user2'
3 'www.kasperksy.com' 'user2'
4 'www.google.com' 'user4' }
out = K(~cellfun('isempty',regexp(K(:,2),'(facebook)|(gmail)')),:)

댓글 수: 1

thanks bobrov for your great response and that too in time

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

추가 답변 (1개)

Karan
Karan 2012년 4월 5일

0 개 추천

one more thing , how to avoid it searching a similar string with something like facebook4you in the above case while i am looking for facebook only

댓글 수: 5

Hi Karan!
out = K(~cellfun('isempty',regexp(K(:,2),'www\.+((facebook)|(gmail))+\.com')),:)
see the attachment and its not working as desired , i dont want the facebook4you.com in the out.
check the scrshot http://i.imgur.com/OKUmX.png
out = a(~cellfun('isempty',regexp(a(:,1),'www\.+((facebook)|(gmail))+\.com')),:)
Or simply regexp(K,'www\.(facebook|gmail)\.com')
silly me .. thanx again bobrov

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

카테고리

도움말 센터File Exchange에서 Software Development Tools에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by