Created
October 1, 2016 13:40
-
-
Save ppizarror/3e724fc177b9c7e384a065026be5e3f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function list = find_coordinates( matrix, value ) | |
%FIND_COORDINATES Encuentra las coordenadas de la posición de un valor VALUE | |
%en la matriz MATRIX | |
% Se obtiene el largo de la matriz | |
l = size(matrix); | |
% Se almacena una lista con todos los valores posibles (coordenadas) | |
coordenates_list = cell(l(1)*l(2),1); | |
% Contador de elementos añadidos | |
total = 1; | |
% Se recorren las filas | |
for i=1:l(1) | |
% Se recorren las columnas | |
for j=1:l(2) | |
if matrix(i,j)==value | |
coordenates_list{total} = [i j]; | |
total = total + 1; | |
end | |
end | |
end | |
% Se crea una lista con todos los elementos añadidos | |
list = cell(total-1,1); | |
for k=1:total-1 | |
list{k} = coordenates_list{k}; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Permite encontrar posiciones (i,j) de un determinado valor value en una matriz nxm matrix