フィルターのクリア

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 Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by