Trying to extract rows of a matrix where a given column equals a range of values
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Michael Bochert
el 10 de Mzo. de 2024
Comentada: Voss
el 12 de Mzo. de 2024
Hi there, I am trying to extract rows of a matrix where the 2nd column of that matrix equals a range of values (i.e., 36-48 for example). I am then only interested in column 9 of those rows.
For example, here is some of the code I have been trying:
YFP_WithmCherry_0_plus = enlistcell_new_YFP_WithmCherry(enlistcell_new_YFP_WithmCherry(:,2)==36:48,9);
I keep getting this error: "The logical indices in position 1 contain a true value outside of the array bounds."
The following code does work, however it doesnt extract all of the rows i want:
YFP_WithmCherry_0_plus = enlistcell_new_YFP_WithmCherry(enlistcell_new_YFP_WithmCherry(:,2)==36,9);
Ive attached the data frame. Please help! Thank you.
0 comentarios
Respuesta aceptada
Voss
el 10 de Mzo. de 2024
Editada: Voss
el 10 de Mzo. de 2024
X = load('enlistcell_new_YFP_WithmCherry.mat').enlistcell_new_YFP_WithmCherry
"2nd column ... equals a range of values (i.e., 36-48... ) ... column 9 of those rows"
One way:
idx = X(:,2) >= 36 & X(:,2) <= 48;
result = X(idx,9)
Another way, since all elements in that range in column 2 are integers:
idx = ismember(X(:,2),36:48);
result = X(idx,9)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!