https://uk.mathworks.com/matlabcentral/answers/394898-excel-matrix-sorting-to-identify-positions
How to get rid of a row if one column is less than a certain value?
3 views (last 30 days)
Show older comments
I have a large data set and need to remove rows of a cell if columns 2 or 3 are less than 10. This is my current script:
clear all
clc
[F,S,R] = xlsread('Matlabhelp.csv');
t = F(:,1);
date = datetime(t, 'ConvertFrom','excel')
% time = F(:,2)/24;
dv = datenum(date);
[dv_sort,idx] = sort(dv);
FinalSorted_1 = [datevec(dv_sort) F(idx,2) F(idx,3)];
FinalSorted_2 = table(datetime(datevec(dv_sort)), F(idx,2), F(idx,3));
acceleration= table2cell(FinalSorted_2);
Accepted Answer
KSSV
on 9 Apr 2018
Let A be your matrix.
% Remove rows if column 2 less then 10
idx = A(:,3)<10 ;
A(idx,:) = [] ;
More Answers (1)
Guillaume
on 9 Apr 2018
You started with a table which are a lot easier to work with than cell arrays, so get rid of the table2cell. For that matter, a lot of the gymnastic could be removed if you used readtable to load the data directly into a table, rather than xlsread. Assuming you're on a recent enough version of matlab, readtable knows how to read dates directly, unlike xlsread.
So:
acceleration = readtable('Matlabhelp.csv');
is probably all that's needed to read the file. If not, post an example of the file. Once that is done, sorting is trivially done:
acceleration = sortrows(acceleration);
and filtering:
acceleration(any(acceleration{:, [2 3]} < 10, 2), :) = []; %delete rows for which any of column 2 or 3 are less than 10
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!