Delete rows from a table below a certain threshold
Show older comments
I have a double table with two columns, Time and Data. I want to delete values out of both columns in the table if it is below a certain value in the 'Data' column. The problem I am encountering is that the data column conatins large values and the time column contains small values so the code I'm using deletes the values from 'Data', working as intended, but then also wipes the entirety of the Time column as all the values are smaller than the threshold. How can I modfiy this to delete Time rows corresponding to the deleted Data rows and leave the rest?
Table = cat(2,Time,Data)
Threshold_Number = T
rowsToDelete = Table < T;
Table(rowsToDelete) = [];
1 Comment
Dyuman Joshi
on 3 Aug 2023
Edited: Dyuman Joshi
on 3 Aug 2023
Numeric data variables are not called Tables in context of MATLAB.
If you have to compare the values in Data column to check, then why are you comparing the threshold with the whole array (3rd line of code above)?
Compare the first row, and use output as the row indices.
Accepted Answer
More Answers (1)
% Make up some example data
Time = [1:10]';
Data = randn(10,1)*10;
Table = cat(2,Time,Data)
Threshold = 8;
% Delete rows where Data is less than threshold
% (actually we are keeping only rows where Data is bigger than threshold)
Table = Table(abs(Data)>Threshold,:)
Here I have followed your code, but I would suggest not calling your variable "Table", when in fact it is an array.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!