Do a loop with a restriction in a duration array
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi I've got a code I want to run it within a time. When the messages are inside a ran of time I want to run my code. 
First I want to run all the messages that are in the first 10 mins then the messages that are within the min 10 and 20. This till the end of the duration variable(1 day).
I post the code and the variables:
lat1 = [];
lon1 = [];
D = minutes(0:10:1439);
D = duration(D,"Format","hh:mm:ss"); %this was created because I thought I could do it with this variable
a = length(D)
for i=1:1:L
    seq1 = msg_NoMatchAIS1(i);
    linia=convertStringsToChars(seq1);
    if linia(13)=='A' && linia(15)=='1'
        sequencia = ais_to_bit(linia(15:44));
            s_longitud=sequencia(62:89);
            longitud = bin2dec(num2str(s_longitud))/600000; % en graus
            lon1 = [lon1, longitud];
            s_latitud=sequencia(90:116);
            latitud = bin2dec(num2str(s_latitud))/600000; % en graus
            lat1 = [lat1, latitud];
    end
end
than you in advance
4 comentarios
  Geoff Hayes
      
      
 el 1 de Feb. de 2022
				But how does an index tell you what time it is? Or do you have one record for each second? Or minute?
Respuestas (1)
  VINAYAK LUHA
      
 el 5 de Dic. de 2023
        
      Editada: VINAYAK LUHA
      
 el 5 de Dic. de 2023
  
      Hi Flashpose,
I understand that you have an array of strings called "msg_NoMatchAIS1short". The indices of this array maps to the timestamps stored in the array called "Time_NoMatchAIS1" array. Further you want to batch process the strings based on 10-minute intervals.
Follow the below steps to batch process the strings every 10-minute interval based on timestamps in the "Time_NoMatchAIS1" array-
- Create an array "lower_bounds" that holds timestamps for each 10-minute interval.
- Then, initialize two variables "x" and "y" to point to the lower and upper indices of data corresponding to any specific 10-minute interval.
- Iterate over the length of the "lower_bounds" array and retrieve the index where the timestamp is just higher than the "lower_bound" for that iteration.
- Update the value of "y" to be "index-1" and retrieve the data using array slicing.
- Update the value of "x" to be "y"+1.
Below is the code snippet implementing the described steps:
durations = Time_NoMatchAIS1;
lower_bounds = minutes(10:10:60);
x = 1;
y = 1;
% Find the indices where lower bounds occur
for i = 1:length(lower_bounds)
    index = find(durations > lower_bounds(i), 1);
    disp(lower_bounds(i));
    y = index-1;
    Intervaldata = msg_NoMatchAIS1short(x:y);
    x =y+1;
    %code to process the data goes below    
end
Hope this helps you to  batch process the strings every 10-minute interval based on timestamps in the "Time_NoMatchAIS1" array.
Regards,
Vinayak Luha
0 comentarios
Ver también
Categorías
				Más información sobre Matrix Indexing en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


