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

2 visualizzazioni (ultimi 30 giorni)
"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

Risposta accettata

Adam Danz
Adam Danz il 10 Ago 2020
Modificato: Adam Danz il 10 Ago 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 Commenti
Adam Danz
Adam Danz il 2 Dic 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by