Logical Indexing for entire Table

137 Ansichten (letzte 30 Tage)
Adam Attarian
Adam Attarian am 24 Okt. 2018
Kommentiert: Leone Campos am 3 Jan. 2023
Essentially, I am trying to do (pseudo code):
T=table(data); % T contains many columns of doubles, date times, and is otherwise numeric.
m = T.field == condition; % Logical indexing based on some field
T=T(m); % implicit application of mask m to each column in T.
Of course, the last line isn't supported by Matlab and returns an error:
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more
subscripts) is not supported. Use a row subscript and a variable subscript.
Is there a way to essentially downsample an entire table based on a logical index mask? It is conceivable that table T has a large (100s) of columns, and manually indexing into each column could be too time consuming.
  1 Kommentar
Ahmed Radwan
Ahmed Radwan am 21 Nov. 2019
Hi, I tried your solution, but it didn't work..
for dp=1:length(DataPoint)
data(dp,:)=adeInfo;
end
I get this error:
Right hand side of an assignment into a table must be another table or a cell array.
adeInfo is not a table. it is as follows, as shown in MATLAB: "A singleton class"

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Attarian
Adam Attarian am 24 Okt. 2018
The solution is simple, and I'm ashamed I didn't see it earlier:
T=T(m,:);
  1 Kommentar
Leone Campos
Leone Campos am 3 Jan. 2023
You shouldn't be ashamed of yourself, you helped me :D

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Monika Lingvay
Monika Lingvay am 11 Nov. 2019
Bearbeitet: Monika Lingvay am 11 Nov. 2019
Thank you, I was looking for the same question and answer!

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by