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

1 Ansicht (letzte 30 Tage)
"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

Akzeptierte Antwort

Adam Danz
Adam Danz am 10 Aug. 2020
Bearbeitet: Adam Danz am 10 Aug. 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 Kommentare
Adam Danz
Adam Danz am 2 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by