Selecting elements of logically pruned vector (concatenating indices)
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi
Given a vector b and a logical vector v_log, is there a straightforward way to extract particular indices of the partial vector b(v_log) without saving it?
In code:
b = randn(20,1); % a vector
v_log = (randn(20,1)>0); % logical vector to select parts of b
ind = [ 2 ; 3 ]; % the elements I'm interested in
c = b(v_log)(ind); % This does not work, but is there a way to do this?
Thanks!
0 Commenti
Risposta accettata
Kelly Kearney
il 12 Gen 2015
I think you'd need to save the indices.
idx = find(v_log);
c = b(idx(ind));
Depending on the size/sparsity of v_log, you may be able to save some time and storage space by only saving the necessary number of indices:
idx = find(vlog, max(ind), 'first');
c = b(idx(ind));
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!