how to create separate events if I have the times at which they start and end in a flow time series data?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I am using a code that gives the times at which an event starts, peaks, and ends. (the result is shown in the pic attached). now i want to separate each event into different variables that has all the timesteps between start and end of the event . the code gives start time for each event in one vector variable called (shloc), end times of each event in another vector variable called (ehloc). the hole dataseries has 43 start points and end points. so i need to get 43 vectors for each event otomatically. if possible in one for loop command. could anyone help with this please?
0 Commenti
Risposte (1)
Arjun
il 25 Mar 2025
I understand that you have 43 start and end points for events, and you want to create dedicated variables for each event, with each variable containing all the time steps for that specific event.
Instead of creating 43 separate variables, it's more efficient to use a cell array with 43 entries, where each entry corresponds to an event and contains all the time steps for that event. Managing a cell array is much easier than handling 43 individual variables, making this the recommended approach.
Assuming a unit distance between successive time steps, I will provide pseudocode for 5 events. You can extend this approach to accommodate 43 events in your situation.
% Define start and end values for the events
start_values = [5, 20, 40, 60, 80];
end_values = [10, 25, 45, 65, 85];
% Cell array to hold each event's time steps
events = cell(length(start_values), 1);
% Loop over each event
for i = 1:length(start_values)
start_value = start_values(i);
end_value = end_values(i);
event = start_value:end_value;
events{i} = event;
end
% Display the extracted events
for idx = 1:length(events)
fprintf('Event %d: ', idx);
disp(events{idx});
end
I hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!