MATLAB: Need Way to calculate Line-of-Sight through Terrain that is faster than los2

los2

Hello,
My code calculates among other things the Line-of-sight from multiple points in an aircraft orbit to a target on the ground. To do this I enter arrays of coordinates into los2. Everything works accurately but the runtime is just unacceptable. To do one orbit against one target takes about 20 seconds. This code will be used with others to test the suitability of several orbits against several targets. Those 20 seconds add up quickly and I'm looking at a code that takes an hour to run a simple case.
Has anyone experienced this slow of a runtime with los2? Is there an alternative method (and/or function) that would be faster than los2?
Any suggestions are welcome!

Best Answer

If you profile a simple example, you'll see that nearly all the computation time of los2 is being spent on the cummax subfunction. There is a built-in cummax.m function, but for some reason (probably legacy), the los2-called function calculateLOS.m has it's own local non-builtin version of cummax that's much, much, much slower than the builtin. I opened the calculateLOS.m file (<matlabroot>/toolbox/map/map/private/calculateLOS.m) and commented out the cummax subfunction at the very end; an los2 call speeds up dramatically after that (I haven't double-checked to make sure the results are the same, so you should definitely do that, though).
The Mapping Toolbox, unfortunately, is full of little inefficiencies like this one, which aren't very noticeable when running toy examples but really add up when trying to apply them to complex datasets.