Need help in indexing
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Ashraf Sherif
 el 11 de Feb. de 2019
  
    
    
    
    
    Comentada: Ashraf Sherif
 el 15 de Feb. de 2019
            Hi all,
I want to index C by M matrixs as below but I have problem in  convert row index into linear index code, I am Using MATLAB R2013a, can any one help me,Thank you in advance
close all
clear all
clc
F=random('exp',1,3,3,4);
C=F*100
M=bsxfun(@times,  C./cumsum(C,3) , reshape(1:4,1,1,[])   )
[vec,idx] = max(M,[],1);      % value and row index of max in each column.
 S = size(M);                 % size of input array.
idx = idx + S(1)*(0:S(2)-1); % convert row index into linear index !!!!!!!!!
 C(idx)                % use linear index to get elements of C.
This are the error message 
Error using  + 
Matrix dimensions must agree.
Error in Untitled6 (line 10)
idx = idx + S(1)*(0:S(2)-1); % convert row index into linear index.
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 12 de Feb. de 2019
        Your M is 4 dimensional . The idx output of max along the first dimension is going to be 4 dimensional . You are trying to add a row vector to it. 
3 comentarios
  Walter Roberson
      
      
 el 14 de Feb. de 2019
				baseidx = idx + repmat((0:size(M,2)-1) * size(M,1),1,1,size(idx,3)) + repmat(reshape((0:size(M,3)-1) * size(M,1)*size(M,2),1,1,[]),1,size(idx,2),1);
rowidx = baseidx + repmat(reshape((0:size(M,1)-1),[],1),1,size(M,2),size(M,3));
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!

