Deleting range of rows in a time series data
7 ビュー (過去 30 日間)
古いコメントを表示
Sewwandhi Chandrasekara
2024 年 6 月 20 日
コメント済み: Sewwandhi Chandrasekara
2024 年 7 月 1 日
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 件のコメント
採用された回答
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:');
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);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!