Generating vector with certain element of matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Say, I have a matrix M = [ 4 5; 10 4; 4 7; 20 6; 4 8 ] I wanna create a vector with 4 (4's that exist only in 1st column) I can't consider 4's from 2nd column of the matrix. Answer will be : V = [4 5 7 8]
By find function, I get [4 5 ; 4 7; 4 8] but how to store them as [4 5 7 8] ?
Another question: side = find(M(1,:) == 4) gives me [4 5 ; 4 7; 4 8]. I have [4 5] already. So, I only want [4 7; 4 8] as output So, how to exclude [4 5] , or first row. I am trying to apply ~ . But, how?
0 Commenti
Risposta accettata
Star Strider
il 17 Mag 2015
This works:
A = [ 4 5; 10 4; 4 7; 20 6; 4 8 ];
N = 4;
Result = [N; A(A(:,1)==N,2)]';
With those column constraints, it is possible to use ‘logical indexing’ to get the result.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!