How to find single index values in a matrix?
    8 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Dalton Houghton-Schaffer
 el 9 de Sept. de 2019
  
    
    
    
    
    Respondida: Walter Roberson
      
      
 el 9 de Sept. de 2019
            B1 = [2 4 6 8; 10 12 14 16; 18 20 22 24; 26 28 30 32]
idx_8=find(B1==8)
[row,column]=find(B1~=8)
RowColumn = [row:column]
Find the single index values for 26, 4, and 28?
How is a matrix indexed with single indexing values?
3 comentarios
  Walter Roberson
      
      
 el 9 de Sept. de 2019
				[was_found, idx] = ismember([26 4 28], B1);
will assign to two variables: was_found and idx. was_found will be true for each element of [26 4 28] that was located somewhere in B1, and will be false for any element that was not found in B1. idx will be 0 for any element that was not found, and otherwise will be the index of the "first" location of the value in B1. idx will be a "linear index"
Respuesta aceptada
  madhan ravi
      
      
 el 9 de Sept. de 2019
        
      Editada: madhan ravi
      
      
 el 9 de Sept. de 2019
  
      https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html - read it for better understanding 
Linear_indices = find(ismember(B1,[26 4 28])); % you mean linear indices by saying single indices
B1(Linear_indices) % would give [26 4 28]
5 comentarios
  Bruno Luong
      
      
 el 9 de Sept. de 2019
				
      Editada: Bruno Luong
      
      
 el 9 de Sept. de 2019
  
			No IMO you should keep it. The difference is interesting to highlight.
Más respuestas (1)
  Walter Roberson
      
      
 el 9 de Sept. de 2019
        [was_found, idx] = ismember([26 4 28], B1);
will assign to two variables: was_found and idx. was_found will be true for each element of [26 4 28] that was located somewhere in B1, and will be false for any element that was not found in B1. idx will be 0 for any element that was not found, and otherwise will be the index of the "first" location of the value in B1. idx will be a "linear index"
0 comentarios
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices 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!



