Effacer les filtres
Effacer les filtres

Remove elements from an array

5 vues (au cours des 30 derniers jours)
Damith
Damith le 17 Mai 2014
Modifié(e) : Image Analyst le 17 Mai 2014
hi,
I have row IDs (or row numbers) of an array. i.e. k=[60:1462:3652136]. I have my YY array [3652500 x 2]. How can I remove the rows of k from YY and store in a different array called XX [2499 x 2].
Can somebody help me with that?
Thanks,
Dumindu.

Réponses (1)

dpb
dpb le 17 Mai 2014
XX=YY(k,:);
I pointed you to this earlier I believe -- look up "logical addressing" in the documentation; it's still a key portion of Matlab syntax.
  2 commentaires
Damith
Damith le 17 Mai 2014
Thanks. But gives me an error "Index exceeds matrix dimensions". First I need to remove rows in k from YY array and then store in XX.
dpb
dpb le 17 Mai 2014
Modifié(e) : dpb le 17 Mai 2014
You've got indices in k that exceed the size(XX,1) so you've got to redefine what you mean.
The length(k) is, as you say, 2499, but from 3652501 on there aren't rows in YY to remove.
I see two ways you can go --
1) If you can live with whatever is in the result array that exists already in YY irrespective of the total elements in XX, then
k=[60:1462:length(YY)];
2) If it's mandatory to have 2499 elements in XX, then
XX=zeros(2499,2); % initialize, any value is ok (use nan(), say)
XX(k,:)=YY(k,:); % k as above
Any similar workaround just so you don't try to reference non-existent elements.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by