Problem when assigning vectors
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (3개)
José-Luis
2012년 11월 2일
b = zeros(numel(f),1);
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!