Reordering column so the values match an already reordered column

1 vue (au cours des 30 derniers jours)
Moey Rojas
Moey Rojas le 27 Mai 2020
Commenté : Star Strider le 27 Mai 2020
Hi, I created a column of serial date numbers from three separate columns and then sorted the serial date numbers in ascending order to plot pCO2 according to serial date number.
DateNumber = datenum[yr, mon, day]
DateNumber2=sort(DateNumber)
scatter(DateNumber, fCO2)
I have a separate column of pH data (fCO2) that matches up with the non-sorted serial date numbers but not the sorted serial date numbers. Is there a way to sort the pH data so that the pH values match with the ascending serial date number values so I can bin the pH values according to month?

Réponse acceptée

Star Strider
Star Strider le 27 Mai 2020
I am not certain what you want to do.
Note that the sort function has two outputs, the first being the sorted values and the second being the original indices of those values. One option is to use the second output as an index into the unsorted array.
Another option is to use the intersect function (with additional index outputs) to identify the matching dates in the ‘fCO2’ data with the ‘pH’ data. Then index them appropriately to get the result you want.
  3 commentaires
Moey Rojas
Moey Rojas le 27 Mai 2020
Great, thank you all so much. I didn't know what indexing was (VERY new to MATLAB), these answers helped a ton.
Star Strider
Star Strider le 27 Mai 2020
Moey Rojas — As always, my pleasure!
Mohammad Sami — Thank you for providing an example.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices 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