example_of_data.PNG
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?

 Akzeptierte Antwort

Adam Danz
Adam Danz am 11 Jun. 2019
Bearbeitet: Adam Danz am 12 Jun. 2019

1 Stimme

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 Kommentare

Thanks! This certainly clears some stuff up. One thing:
m(ismember(m(:,7),badMonths),7) = []; %get rid of rows with bad months
This line returned "A null assignment can have only one non-colon index"
Not exactly sure how to proceed here
Opps. There was a typo in my code. I updated it.
% old version:
m(ismember(m(:,7),badMonths),7) = [];
%New, correct version
m(ismember(m(:,7),badMonths),:) = [];
% ^ correction
Alex Herron
Alex Herron am 12 Jun. 2019
This worked perfectly, much appreciated!
Adam Danz
Adam Danz am 12 Jun. 2019
Bearbeitet: Adam Danz am 15 Jan. 2020
Glad I could help!
Alex Herron
Alex Herron am 12 Jun. 2019
you got it

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by