Finding both row and column indexes of nearest value
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Luís Henrique Bordin
 el 2 de Abr. de 2024
  
    
    
    
    
    Comentada: Image Analyst
      
      
 el 3 de Abr. de 2024
            Hi experts,
Please, could someone help me to find the 2 indexes, that is, the row and column indexes, corresponding to the nearest longitude and/or latitude? I could figure it out easily in a vector of 1D with find and dsearchn functions, but the problem is I cannot simply transform my matrix into a vector because longitude and latitudes are not constant all along the same row and column.
I have two matrices, one for the longitude, and another for the latitude. Both matrices are 224x164.
I need the row and column indexes of the nearest longitude of 25.983 on the longitude matrix; And idem for the latitude -84.64.
Thank you very much in advance!
Luis
0 comentarios
Respuesta aceptada
  Image Analyst
      
      
 el 2 de Abr. de 2024
        To find the nearest row and column, subtract the reference value from your matrix and then use find.  To be super explicit, here are the steps:
m = magic(7)
refValue = 27;
diffMatrix = abs(m - refValue)
minDifferenceValue = min(diffMatrix, [], 'all')
[row, column] = find(diffMatrix == minDifferenceValue)
4 comentarios
  Image Analyst
      
      
 el 3 de Abr. de 2024
				OK.  Next time, include your data so we can get you answer(s) right away with your own actual data.
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!


