필터 지우기
필터 지우기

Problem when assigning vectors

조회 수: 1 (최근 30일)
Mike
Mike 2012년 11월 2일
Hi,
i want to do this:
b=zeros(size(f),1)
b=f(k);
And i get this error:
Index exceeds matrix dimensions.
I print the size of each variable and this is the result:
size(f)= 500 1;
size(k)= 500 1;
size(b)= 500 1; %Here, i get this warning:
%Warning: Input arguments must be scalar.
Can anyone explain me why am i returned this result? How could i fix my mistake and make b=f(k); works??
Thank you in advance.
  댓글 수: 3
Mike
Mike 2012년 11월 2일
Which ones?? f?? Do you want results of my signal f?? or my signal?
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 2일
f and k

댓글을 달려면 로그인하십시오.

답변 (3개)

John Petersen
John Petersen 2012년 11월 2일
the value of k must be positive and less than the size of f.
  댓글 수: 1
Mike
Mike 2012년 11월 2일
Thank you, but how could i fix the error. I do not understand why this error exists as each vector has size [ 500 1 ].

댓글을 달려면 로그인하십시오.


José-Luis
José-Luis 2012년 11월 2일
b = zeros(numel(f),1);
  댓글 수: 3
José-Luis
José-Luis 2012년 11월 2일
편집: José-Luis 2012년 11월 2일
Try
max(k)
Given your error, the value returned should be larger than the size of f. You are trying to access elements of f beyond the defined range. I recommend you read the getting started part of the documentation to understand indexing.
Mike
Mike 2012년 11월 2일
Thank you for your help.

댓글을 달려면 로그인하십시오.


Loren Shure
Loren Shure 2012년 11월 2일
First, Mike, there is no reason to preallocate the vector b with zeros since you overwrite the variable in the next statement.
Second, as pointed out above, the first input to zeros needs to be a scalar value.
And finally, also pointed out above, the value for k can't exceed the number of values in f.
So, I guess (and I think others above have too) that your value for k is larger than the number of elements in f. Perhaps you can post a bit more of the code so we can see better what is happening.
  댓글 수: 1
Mike
Mike 2012년 11월 2일
Thank you for your reply. I just try to preallocate the b in case i fix tmy mistake. But, i understand it is not needed.
I write:
display(max(k));
and i got the result: 4991. So, you are right.
Thank you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by