Finding values corresponding to row and column index of a matrix
    12 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Hari krishnan
 el 31 de Mayo de 2020
  
    
    
    
    
    Respondida: Thiago Henrique Gomes Lobato
      
 el 31 de Mayo de 2020
            I have a matrix 'A'. I would like to find the elements in 'A', corresponding to the indices given in 'row_index' and 'col_index'.
The required output is shown as; 'out'
A = [1 12 23 19 1  13;
2 3  13 34 5  75;
5 22 45 5  1  94;
4 5  68 2  5  17;
2 4  34 11 13 92];
row_index = [4,5,5];
col_index = [3,4,5];
out  = [68,11,13]; 
0 comentarios
Respuesta aceptada
  Thiago Henrique Gomes Lobato
      
 el 31 de Mayo de 2020
        A = [1 12 23 19 1  13;
2 3  13 34 5  75;
5 22 45 5  1  94;
4 5  68 2  5  17;
2 4  34 11 13 92];
row_index = [4,5,5];
col_index = [3,4,5];
ind = sub2ind(size(A),row_index,col_index);
A(ind)
ans =
    68    11    13
0 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!

