first of all take my appoligy for my bad english.
I am trying to optimize par of my code using cellfun. (Now I know cellfun is not going to optimize perfomance, just shorten the code).
l = [1,20,10,1];
for k=1:length(edg)
    e = edg{k};
    d = lineSegmentIntersect(l, e);
    d2 = lineSegmentIntersect([l(3) l(4) l(1) l(2)], e);
    if d.intAdjacencyMatrix
        if d.intMatrixX == e(1) && d.intMatrixY == e(2) ||  d.intMatrixX == e(3) && d.intMatrixY == e(4)
        else
            it = 1; 
            break;
        end
    elseif d2.intAdjacencyMatrix  
        if d2.intMatrixX == e(1) && d2.intMatrixY == e(2) ||  d2.intMatrixX == e(3) && d2.intMatrixY == e(4)
        else
            it = 1;
            break;
        end
    end
end
I mannaged to calc lineSegmentIntersect for each l,edg pair,
d = cellfun(@(x) lineSegmentIntersect(x,l),edg);
d2 = cellfun(@(x) lineSegmentIntersect(x,[l(3) l(4) l(1) l(2)]),edg);
but I cannot find any information on how to use conditions inside the cellfun. Is it even possible? (this is not relevant anymore)
If not, is there any other way of optimizing this?
Function lineSegmentIntersect returns a struct, from which I am using 3 properties for my conditions:
- intAdjencyMatrix (if 1 the segments intersects)
- intMatrixX (x coordinate of the intersection)
- intMatrixY (y coordinate of the intersection)
If l intersects one of the edg, than I want to return 1.
Would be realy greatful for any hints.
UPDATE: I tried to use vectorization but I cannot find a similar case, or this one is just to complex for vectorization?.
Thanks alot!
