Find longest consecutive sequence in 3d matrix

5 ビュー (過去 30 日間)
Elin Jacobs
Elin Jacobs 2021 年 11 月 22 日
コメント済み: Elin Jacobs 2021 年 11 月 29 日
I have a large 3d matrix (latitude x longitude x time) and need to find the longest consecutive time sequence of values <=1 for each latitude/longitude pair. I have a dummy code that works on 1d data, but I am struggling to translate it to my 3d data. Also attaching a smaller piece of my 3d data file. Any help appreciated.
Dummy 1d code:
x = [0.1 1 0.1 0.11 0.3 3 0.1 11 0.3 0.3 0.3 0.13 10 1 0.3 3 3 0.1 0.1 3 3]; %made up numbers
x(x <= 1) = 0; % setting al values <=1 to 0
f = find(diff([1,x,1]==0));
p = f(1:2:end-1); % Start indices
y = f(2:2:end)-p; % Consecutive zeros
dry_max = max(y); %calculate longest sequence of 0s
  3 件のコメント
Elin Jacobs
Elin Jacobs 2021 年 11 月 29 日
The attached data file contains rainfall data at the daily time scale for one year (third dimension). I want to find the longest sequence of no rainfall (or rainfall less than 1 mm) at each latitude and longitude (first and second dimension). So the result I want (using the example data file) is a 20 by 30 matrix with a single value for the maxiumum number of days with no rain at each lat/lon pair. I hope that makes it more clear. Thank you.



Matt J
Matt J 2021 年 11 月 29 日
編集済み: Matt J 2021 年 11 月 29 日
  1 件のコメント
Elin Jacobs
Elin Jacobs 2021 年 11 月 29 日
This works great, thank you very much!


その他の回答 (0 件)




Community Treasure Hunt

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

Start Hunting!

Translated by