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

3 vues (au cours des 30 derniers jours)
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]

Réponse acceptée

Turlough Hughes
Turlough Hughes le 18 Sep 2020
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 commentaires
Walter Roberson
Walter Roberson le 18 Sep 2020
To extract "across" instead of "down",
Vt = V.';
Vt(logicalVec.')
Mithushan Kanthasamy
Mithushan Kanthasamy le 18 Sep 2020
thank you!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by