Generating vector with certain element of matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tanmoy
am 17 Mai 2015
Kommentiert: Star Strider
am 17 Mai 2015
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 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Mai 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.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!