Problem when assigning vectors
Mostra commenti meno recenti
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 Commenti
Azzi Abdelmalek
il 2 Nov 2012
can you post a sample of your data
Mike
il 2 Nov 2012
Azzi Abdelmalek
il 2 Nov 2012
f and k
Risposte (3)
John Petersen
il 2 Nov 2012
1 voto
the value of k must be positive and less than the size of f.
1 Commento
Mike
il 2 Nov 2012
José-Luis
il 2 Nov 2012
b = zeros(numel(f),1);
Loren Shure
il 2 Nov 2012
1 voto
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 Commento
Mike
il 2 Nov 2012
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!