Wrong way to index: Index exceeds matrix dimensions
    조회 수: 10 (최근 30일)
  
       이전 댓글 표시
    
Hi,
I'm trying to use indices to expand a vector but I keep getting an error message and I don't understand why. In particular, what I'm trying to do works in an example such as
x=[1 2 3]';
y=[.1 .5 .3]';
z=[1 1 2 2 3];
yz=y(z);
Here I have two vectors, x and z that have the same values for the indices. I want to expand the vector y to have the same dimensions as z but the values of z must be repeated according to how the index is repeated.
Now, in my application this is not working. I have two vectors X and Z, X of dimensions 2270x1 and Z of dimensions 446723x1 that contains the same indices as X but a lot of times (and each number is repeated a different number of times). To check that the indices are the same I used isequal(unique(X),unique(Z)) and the output was 1.
Finally, I have a vector Y of dimensions 2270x1 that plays the role of y in the example above. When doing YZ=Y(Z) I get ??? Index exceeds matrix dimensions.
Any ideas what is going on?
Thanks,
댓글 수: 0
채택된 답변
  ChristianW
      
 2013년 3월 20일
        max(Z) is greater then 2270?
댓글 수: 3
  Hideto Koizumi
 2018년 8월 28일
				
      편집: Hideto Koizumi
 2018년 8월 28일
  
			I think this method could cut off the largest element of z, if z is something like z = [1 1 2 4] and y=[.1 .5 .3 .7]';
추가 답변 (2개)
  Azzi Abdelmalek
      
      
 2013년 3월 20일
        
      편집: Azzi Abdelmalek
      
      
 2013년 3월 20일
  
      Check this
size(Y)
max(Z)
What did you get?
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



