Problem when assigning vectors
Afficher commentaires plus anciens
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 commentaires
Azzi Abdelmalek
le 2 Nov 2012
can you post a sample of your data
Mike
le 2 Nov 2012
Azzi Abdelmalek
le 2 Nov 2012
f and k
Réponses (3)
John Petersen
le 2 Nov 2012
1 vote
the value of k must be positive and less than the size of f.
1 commentaire
Mike
le 2 Nov 2012
José-Luis
le 2 Nov 2012
b = zeros(numel(f),1);
Loren Shure
le 2 Nov 2012
1 vote
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 commentaire
Mike
le 2 Nov 2012
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!