Converting a the result vector from logical indexing into a matrix possible or unnescesary?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel
am 4 Dez. 2013
Kommentiert: Daniel
am 7 Dez. 2013
Hello everyone,
I need to extract rows of a matrix with a certain value in one column. At the moment I am using logical indexing i this way:
c=A(:,2)==3; T=A([c,c,c,c]);
The problem I have is that T is a vector, with the columns added end to end, but I need it as a matrix.
Does Matlab provide an easy way to convert such a vector to a matrix or is there another easy way to extract the rows into a matrix?
Thank you everybody.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Jos (10584)
am 7 Dez. 2013
Often, you get some insight when you remove the semi-colons
A = [1 2 3 4 ; 11 3 13 14 ;21 22 23 24 ; 41 3 43 44] % example data
c = A(:,2)==3
T = A(c,:)
if T is empty, there are simply no rows that have a value of 3 in the second column.
Siehe auch
Kategorien
Mehr zu Logical 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!