Info

This question is closed. Reopen it to edit or answer.

Extract certain rows of matrix if they have a certain number

1 view (last 30 days)
I have a large set of data of hourly data taken over a few years. I'm trying to extract only afternoon hour data into a new matrix. Data looks like this:
M = [ 1 2011 1 0 399
1 2011 1 2 440
1 2011 1 3 430]
I'm trying to extract the rows that have numbers 17-21 in column 4 into a new matrix.

Answers (1)

Walter Roberson
Walter Roberson on 17 Mar 2019
Edited: Walter Roberson on 17 Mar 2019
mask = ismember(M(:,4), 17:21);
afternoon_M = M(mask,:);
There are other ways to write the test, such as
mask = M(:,4) >= 17 & M(:,4) <= 21;

Tags

Community Treasure Hunt

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

Start Hunting!