How can I delete an entire row/element of a matrix/array and also delete the same row/element from another matrix/array?

2 vues (au cours des 30 derniers jours)
"rawData, "TDT1," and "TDT2" are 1-D arrays/columns of numbers of identical length.
Each array represents a different parameter. The first element of each array represents a measurement taken at a particular time. The second element of each array represents a measurement taken at a new time, and so on.
My problem is that there can be elements in each array equal to "9999," which means that a measurement failed to happen.
  • I need to delete elements where the value is "9999."
  • Then I also need to delete the same elements/rows from the other two arrays/columns.
  • In the end, I need the three arrays to have the same length and no "9999" values.
Does anyone know how I can do this? I have Matlab 2016b. I have so far managed the below, but there are key steps missing.
rawData(rawData == 9999) = nan; TDT1(TDT1 == 9999) = nan; TDT2(TDT2 == 9999) = nan; % Here I turn the number "999" into "nan" in all three arrays.
% I don't know how to delete a "nan" element from one array and also delete the same element from the other two arrays.
Thank you for any help

Réponse acceptée

Adam Danz
Adam Danz le 10 Août 2020
Modifié(e) : Adam Danz le 10 Août 2020
Since the column vectors should be the same length, I recommend you combine them into a matrix (shown below) or a table.
m = [columnVector1, columnVector2, columnVector3];
Then compute which rows have 9999 values.
removeRowIdx = any(m==9999,2);
Then delete those rows
m(removeRowIdx,:) = [];
or replace with NaN values
m(removeRowIdx,:) = NaN;
If you decide to keep the column vector variables separate, you can use the same approach,
removeRowIdx = columnVector1==9999 | columnVector2==9999 | columnVector3==9999;
columnVector1(removeRowIdx) = []; % or = NaN
columnVector2(removeRowIdx) = []; % or = NaN
columnVector3(removeRowIdx) = []; % or = NaN
  6 commentaires
Adam Danz
Adam Danz le 2 Déc 2021
Yes and I'd be happy to help you do the same. Give it a shot and share what you've got if you get stuck.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by