How can I select or extract rows?

1 view (last 30 days)
I have a 9855 * 1 table indicating months.
Such as
1
1
1
2
2
2
3
3
3
. .
12
12
12
1
1
1
2
2
2
...
How can I select or extract June to August?

Accepted Answer

Star Strider
Star Strider on 6 Sep 2022
It depends on what the data are (for example, datetime arrays).
Given the problem described —
Months = repmat(ones(3,1) * (1:12), 1, 5);
Data = [Months(:) (1:numel(Months)).']
Data = 180×2
1 1 1 2 1 3 2 4 2 5 2 6 3 7 3 8 3 9 4 10
% Check1 = Data(24:36,:)
Result = Data(6 <= Data(:,1) & Data(:,1) <= 8, :)
Result = 45×2
6 16 6 17 6 18 7 19 7 20 7 21 8 22 8 23 8 24 6 52
Check2 = Result(28:36,:)
Check2 = 9×2
6 124 6 125 6 126 7 127 7 128 7 129 8 130 8 131 8 132
There are other approaches as well. this is likely the simplest.
.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!