Sorting data in large data set
8 views (last 30 days)
Show older comments

I'm working with a large (78024x7 cell array) data set and I'm trying to trim it down a bit. The first column is depth and the seventh column is month (numerical). One way to shave down this data is by getting rid of all the March, April, May, September, October, & November values (3,4,5,9,10,11), as I do not need these values. Furthermore, any data point below the depth of 400 is useless to me.
I'm looking to eliminate all the rows that fit this criteria in order to make this data set easier to work with, but I'm having trouble getting started. Any tips?
0 Comments
Accepted Answer
Adam Danz
on 11 Jun 2019
Edited: Adam Danz
on 12 Jun 2019
The data in the image you shared appear to be in a spreadsheet and surrounded by single quotes. I'll assume you've imported those data into matlab. You menionted your data is stored in a cell array. If your cell array contain strings (due to the single quotes) you can convert those data to a matrix by using str2double(). If the cell array contains numeric data, you can convert that to a matrix using cell2mat().
m = str2double(data);
m = cell2mat(data);
Once you have a matrix, you can eliminate rows of data like this
badMonths = [3,4,5,9,10,11];
depthMax = 400;
m(ismember(m(:,7),badMonths),:) = []; %get rid of rows with bad months
m(m(:,1)>depthMax,:) = []; %get rid of rows with depths > 400
*Update: Corrected one character in the block above (explained below in comments).
5 Comments
More Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!