选择第一列值在列表中至少出现一次的行

时间:2017-01-17 15:56:46

标签: arrays matlab matrix any

假设:

A

我尝试选择所有矩阵id行,如果第一列的值至少出现在A = 1 22 33 2 44 55 2 66 77 一次,而不使用循环。

因此,从:

开始
2    44    55
2    66    77

在这个例子中我想得到以下内容:

# Load your RSA pub and private keys
pubKey = jwk.JWK().from_pyca(serializedPublicKey)
privateKey = jwk.JWK().from_pyca(serializedPrivateKey)

# your JWT claims go here
claims = {
    # JWT claims in JSON format
          }
# sign the JWT
# specify algorithm needed for JWS
header = {
          u'alg' : 'RS256', 
          'customSigHeader':'customHeaderContent'
          }
# generate JWT
T = jwt.JWT(header, claims)
# sign the JWT with a private key
T.make_signed_token(privateKey)
# serialize it
signed_token = T.serialize(compact=True)

# JWE algorithm in the header
eprot = {
    'alg': "RSA-OAEP", 
    'enc': "A128CBC-HS256",
     'customEncHeader':'customHeaderContent'
     }   
E = jwe.JWE(signed_token, json_encode(eprot))
# encrypt with a public key
E.add_recipient(pubKey)#
# serialize it
encrypted_signed_token = E.serialize(compact=True)

更简单的方法是什么? 非常感谢。

1 个答案:

答案 0 :(得分:4)

使用ismember创建一个选择行的逻辑索引:

A(ismember(A(:,1), id),:)

或者,您可以使用anybsxfun(@eq, ...)代替ismember

A(any(bsxfun(@eq, A(:,1).', id(:)), 1), :)

或者,从Matlab版本R2016b开始,由于implicit singleton expansion,您可以仅bsxfun(@eq, ...)替换==

A(any(A(:,1).'==id(:), 1), :)
相关问题