how to get character from an array using another logical array?

how to get character from an array using another logical array?
for example
V = '1b.%291x g'
'yig&aaSgwa'
'tqtbbs!?R!'
logicalVec = [ 1 0 1 0 1 0 1 0 1 1; 0 1 1 0 1 0 0 0 1 1; 1 0 1 0 0 1 1 1 0 1]

 採用された回答

Turlough Hughes
Turlough Hughes 2020 年 9 月 18 日

0 投票

A slight modification on your inputs:
V = ['1b.%291x g'; 'yig&aaSgwa'; 'tqtbbs!?R!'];
logicalVec = logical([ 1 0 1 0 1 0 1 0 1 1; 0 1 1 0 1 0 0 0 1 1; 1 0 1 0 0 1 1 1 0 1]);
You can then use a logical index to find the characters corresponding to true values:
V(logicalVec).'

3 件のコメント

Mithushan Kanthasamy
Mithushan Kanthasamy 2020 年 9 月 18 日
Linear indices automatically go down the columns of an array. how might you make them
go down the rows?
Walter Roberson
Walter Roberson 2020 年 9 月 18 日
To extract "across" instead of "down",
Vt = V.';
Vt(logicalVec.')
Mithushan Kanthasamy
Mithushan Kanthasamy 2020 年 9 月 18 日
thank you!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by