constructing sequence of ismember

Hi all,
I have the vector A=
l1
‘l2’
‘Kl9’
‘E9’
In my case, A contains hundreds of different elements (‘l1’,‘l2’,…). I want to produce a series of
lopp(ismember(c,{'x' })) where x stands for each element of A So I want to have
B=[ lopp(ismember(c,{'l1' })) lopp(ismember(c,{'l2' })) lopp(ismember(c,{'KI9' })) lopp(ismember(c),{'E9' }))…]
Is there any code that will enable me to construct B automatically
thanks

답변 (1개)

Walter Roberson
Walter Roberson 2012년 5월 23일

0 개 추천

[tf, idx] = ismember(c, A);
B = lopp(idx(tf))

댓글 수: 9

antonet
antonet 2012년 5월 23일
HI walter, for some reason I do not get the same result
antonet
antonet 2012년 5월 23일
Just to say that c is a vector
Walter Roberson
Walter Roberson 2012년 5월 23일
I will cross-check later when I'm at my desk.
antonet
antonet 2012년 5월 23일
I really t thank you.
Walter Roberson
Walter Roberson 2012년 5월 23일
Try
[tf, idx] = ismember(A,c);
B = lopp(idx(tf));
antonet
antonet 2012년 5월 23일
Hi walter. Again, the results are not the same
antonet
antonet 2012년 5월 23일
to clarify some things. the vector c is
'l1'
'l1'
'l1'
'l1'
'l1'
'l1'
'l1'
'l1'
'l1'
'l2'
'l2'
'l2'
'l2'
l3'
'l3'
'l3'
'l3'
'l3'
and the lopp is
[11.9154]
[11.4014]
[10.8762]
[10.5987]
[10.2064]
[10.0170]
[10.3118]
[10.9467]
[11.4735]
[11.2132]
Walter Roberson
Walter Roberson 2012년 5월 23일
There are repeats in c ? Hmmm, I'll have to think about this a bit more.
antonet
antonet 2012년 5월 24일
yes i have repeated l1s l2s l3s l4s and l5s in c. thank you again

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2012년 5월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by