Find longest consecutive sequence in 3d matrix
    7 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Elin Jacobs
 am 22 Nov. 2021
  
    
    
    
    
    Kommentiert: Elin Jacobs
 am 29 Nov. 2021
            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 Kommentare
  Dyuman Joshi
      
      
 am 24 Nov. 2021
				How exactly do you want to find the longest consecutive sequence in 3D data? What will be the order of the sequence? Can you show an example? 
Akzeptierte Antwort
  Matt J
      
      
 am 29 Nov. 2021
        
      Bearbeitet: Matt J
      
      
 am 29 Nov. 2021
  
      Using,
[M,N,P]=size(prec);
prec=permute(prec,[3,1,2]);
prec=prec(:,:)<=1;
prec(end+1,:)=0;
[starts,stops,runlengths]=groupLims(groupTrue(prec(:)),1);
A=accumarray(starts,runlengths,size(prec(:)));
A=ipermute(reshape(A,[P+1,M,N]),[3,1,2]);
[dry_max,p]=max(A,[],3);
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!


