Get the numbers of rows where values change

5 vues (au cours des 30 derniers jours)
Maja Zdulska
Maja Zdulska le 16 Juil 2020
Commenté : Maja Zdulska le 16 Juil 2020
Hi,
I have an array of data, structured like this:
Latitude Longitude Height
23 54 7
23 54 3
23 54 8
23 55 4
23 55 2
24 54 0
24 54 1
24 55 2
24 55 7
How can I get the numbers of the rows where either Latitude or Longitude changes (so from the example above the output would be rows 3, 5 and 7)?
  2 commentaires
Image Analyst
Image Analyst le 16 Juil 2020
By the time you get down to row 3, nothing has changed yet. Row 3 is still the same as rows 1 and 2. Don't you mean 4, 6, and 8? Those are the actual rows where a change is first encountered.
Maja Zdulska
Maja Zdulska le 16 Juil 2020
Yes, sorry, you're absolutely correct.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 16 Juil 2020
By the time you get down to row 3, nothing has changed yet. Row 3 is still the same as rows 1 and 2. Don't you mean 4, 6, and 8? Those are the actual rows where a change is first encountered.
Try this:
m = [
23 54 7
23 54 3
23 54 8
23 55 4
23 55 2
24 54 0
24 54 1
24 55 2
24 55 7]
latChanged = [0; diff(m(:, 1))] % Logical -- use find() if you want row numbers.
lonChanged = [0; diff(m(:, 2))] % Logical -- use find() if you want row numbers.
eitherChanged = find(latChanged | lonChanged) % Row numbers where either lat OR lon changed.

Plus de réponses (1)

David Hill
David Hill le 16 Juil 2020
b=diff(a);%a being your matrix
c=find(b(:,1)~=0|b(:,2)~=0);%c=3,5,7

Catégories

En savoir plus sur Cell 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