MATLAB Answers

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

1 view (last 30 days)
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]

  0 Comments

Sign in to comment.

Accepted Answer

Turlough Hughes
Turlough Hughes on 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 Comments

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

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by