Deleting range of rows in a time series data

7 次查看(过去 30 天)
I have time series of rainfall data. The column 1=year, 2=month, 3=date (from 1 to 31), 4=daily rainfall value. I want to remove the rows which have range of data from year 1995 to 2016. I managed to do for one year. But not for range. How can I do so? Many thanks in advance.
RF(find(RF==1([1995:2016],:)=[] I did this code, but says error of using : inbetween 1995 & 2016

采纳的回答

Anurag Ojha
Anurag Ojha 2024-6-20
Hey
To remove the rows with a range of years from 1995 to 2016, you can use logical indexing in MATLAB. Here's an example code snippet that demonstrates how to achieve this:
I have taken a simpler sample data, Kindly modify the code as per your use case:
% Sample data creation
% Columns: year, month, date, daily rainfall value
data = [
1990, 1, 1, 10;
1992, 5, 15, 5;
1995, 7, 21, 12;
2000, 2, 11, 8;
2010, 8, 23, 7;
2016, 12, 31, 20;
2017, 3, 14, 3;
2020, 6, 5, 15;
2022, 10, 19, 4;
];
% Display the original data
disp('Original Data:');
Original Data:
disp(data);
1990 1 1 10 1992 5 15 5 1995 7 21 12 2000 2 11 8 2010 8 23 7 2016 12 31 20 2017 3 14 3 2020 6 5 15 2022 10 19 4
% Create a logical index for rows that fall outside the range 1995-2016
index = (data(:, 1) < 1995 | data(:, 1) > 2016);
% Remove the rows that satisfy the logical index
filtered_data = data(index, :);
% Display the filtered data
disp('Filtered Data:');
Filtered Data:
disp(filtered_data);
1990 1 1 10 1992 5 15 5 2017 3 14 3 2020 6 5 15 2022 10 19 4

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by