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

2 次查看(过去 30 天)
"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

采纳的回答

Adam Danz
Adam Danz 2020-8-10
编辑:Adam Danz 2020-8-10
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by