Deleting range of rows in a time series data
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sewwandhi Chandrasekara
am 20 Jun. 2024
Kommentiert: Sewwandhi Chandrasekara
am 1 Jul. 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
0 Kommentare
Akzeptierte Antwort
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:');
disp(data);
% 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:');
disp(filtered_data);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!