How to retrieve location values in a matrix
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Danish Nasir
 el 24 de Jul. de 2021
  
    
    
    
    
    Comentada: Danish Nasir
 el 24 de Jul. de 2021
            Suppose i have a matrix 4x6 i.e. 6 columns and 4 rows. I want to extract different location values from the matrix i.e. 3rd location from column 1, 4th location value from column 2, 1st location value from column 3 etc. ([ 3 4 1 5 2 2]). Then i have to add these column location values. Pls suggest the code.
0 comentarios
Respuesta aceptada
  Chunru
      
      
 el 24 de Jul. de 2021
        % Generate a 4X6 matrix
a = randi(10, 4, 6)
% The index to each column
%idx = [ 3 4 1 5 2 2]       % 5 is not correct
idx = [ 3 4 1 4 2 2];
% Fund the corresponding linear index
ii = sub2ind([4, 6], idx, 1:6);
% Show the extracted data
a(ii)
sum(a(ii))
Más respuestas (1)
  Sulaymon Eshkabilov
      
 el 24 de Jul. de 2021
        % e.g.:
A = randi([0, 13], 4,6)
A(3,1), A(4, 2), A(1,3)
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!

