Novice_Developer
Novice_Developer

Reputation: 1492

Find a condition row by row

Consider the following example

disp('Tag1Number      Tag2number')
for i = 1:numel(T1starttime)
    indexPDfind = find(T1starttime(i)<T2starttime & T2endtime<T1endtime(i));
    if(~isempty(indexPDfind))
        fprintf(' %d              %d\n',i,indexPDfind.')
    end

end

Where T1starttime T2starttime T1endtime are tags of timestamps vectors , I am trying to find the tags T2 which are with in T1 tags , Initially I am trying to find the start time of tags T2 within each tag1 of T1 , The above code works fine , but the number of tags can be very high and I dont want to use a loop , Is there any function like bsxfun() which will go row by row to find the certain index

Upvotes: 1

Views: 53

Answers (1)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

Yes, you can do this with bsxfun, I believe the relevant functions are gt and lt.

This may speed up the calculation a bit, but for big inputs (where most can be gained) memory might become an issue.

However, for medium/small sizes, the main performance improve that you will get will not likely come from this. You currently do a print each time you find a result.

Printing 1 thing is horribly slow, make sure to store all your results and print them at the end in 1 time to get a proper speedup.

Upvotes: 1

Related Questions