Modifying the array with numerical values in the vicinity of the elements in earlier array
1 view (last 30 days)
I don't know if it is clear from title what I actually want to ask.
I am trying to plot rectangular pulses. I simple dont want any of the plotted pulses to overlap.
The thing is, the start times of the pulses are calculated from some program. When I find the pulses for next user then these instances are overlapping (in multiple ways) with the earlier instances. Following is the code.
GlobIWC=zeros(1,86400); % First I am defining global instance vector
NZGlobIWC=find(GlobIWC) % Global Instance Start time vector-Only non zero elements of Global vector are extracted.
NZGlobFWC=find(GlobIWC) % Global Instance End time vector
% These vectors are just to initialize the loop in the program
users=[1 2 3 4 5 6]
% some code
WCId=[3437 68688 77158 79405] % I get these location of instances on time scale(0-24 hrs) from 1 to 86400 for this current user
Dur=240; % this will be the duration of Pulse in seconds
FWCId=WCId+Dur; % this will be the end time location of the pulse
FWCId=[34619 68928 77398 79645] % this is End instance vector
% Overlap removal loop
if ((NZGlobIWC(ii)-Dur) < WCId(jj)) && (WCId(jj)< (NZGlobFWC(ii)+Dur)) || ((NZGlobIWC(ii)-Dur) < FWCId(jj)) && (FWCId(jj)< (NZGlobFWC(ii)+Dur))
WCId(jj) = NZGlobFWC(ii) + Dur +randi ([240 600]); %In this middlmost loop I tried to use "for"instead of "if"
% In above loop, I try to block the Time location from Global Non-zero vector in a passage (NZGlobIWC-dur) to (NZGlobIWC-dur) for
% both start time (WCId) and end time (FWCId) of the New pulse and assign WCId a new value which is some random time after the end of
% earlier pulse
GlobIWC(WCId(ii))=WCId(ii); % Here I add the new elements to the global instance of use vector,
% Some code
Dur= 120; % Now the new value of Dur is calculated here.
NZGlobIWC=find(GlobIWC); % The new Non zero instance vectors for both start and end time are created here
for kk=1 :length(WCId)
One thing I found is, in overlap removal loop, I check the current instance(WCId) with Global instances(NZGlobIWC), but I dont check this newly formed instanes (modified WCId) again with the NZGlobIWC. This is what might be causing problem. I tried to use "while" loop in the Overlap removal. But it takes like forever to end the loop . As this is just a very small part of my program I need computationally efficient way to resolve this seemingly complex issue.
How can I stop overlapping of these pulses?
P.S. Attached in the expected figure .