How to find all rows and columns that contain a specific value in MATLAB
56 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jack Bryant
el 14 de Feb. de 2020
Respondida: Star Strider
el 14 de Feb. de 2020
Hello
I have a 1000 x 1000 table consisting of 1s and 0s. I want to find every row and column that consists of at least one 1 and return the indexes of them all in an array (e.g. [1 5 7 62 299 430 827]). How do I go about doing this?
Thank you
1 comentario
Lianne Abrahams
el 14 de Feb. de 2020
Using for loops, but I don't know exactly how. I have a similar problem; I wish to sum all elements for which the row index is equal to or greater than the column index.
Idk how to specify indexing on a conditional basis, up to now we have only been shown how give absolute index values like X(1,2)
Respuesta aceptada
Star Strider
el 14 de Feb. de 2020
Try this:
A = randi([0 1], 10, 5); % Create Array 'A'
A([4 8],:) = zeros(2,5); % Set Rows #4 & #8 Arbitrarily To All 0
B = find(any(A,2));
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays 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!