Deleting range of rows in a time series data

7 Ansichten (letzte 30 Tage)
Sewwandhi Chandrasekara
Sewwandhi Chandrasekara am 20 Jun. 2024
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

Akzeptierte Antwort

Anurag Ojha
Anurag Ojha am 20 Jun. 2024
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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by