I have a function which in total takes 34s and I want to speed this up. The 2 slowest functions are:
1) I have a very simple function file:
function [x] = percentChange(startPoint, currentPoint)
x = ( (currentPoint-startPoint)/abs(startPoint) )*100.00;
where currentPoint and startPoint are just integers. During my main function I call this function 1.114.239 times (which takes my computer 13.364s). Can I make this any faster?
2) Another part of my function which takes quite a while is the plotting of 1934 lines. Currently, the plotting is done as follows:
for i=1:size(patternPlot,1)
hold all
plot(xplot,patternPlot(i,:));
end
'patternPlot' stores the vectors i want to plot (xplot is just the vector 1:30). Can I speed this up in any way?
Thanks in advance,
J
In 1): remove outer parentheses in second line. Probably won't gain speed; just for clarity.
Do you really have to call that function so many times, each with a number? Can't you do (currentPoint-startPoint)./abs(startPoint)*100.00
where currentPoint
and startPoint
are vectors?
In 2): instead of the loop do a single, "vectorized plot": plot(xplot,patternPlot)
, or better plot(patternPlot.')
. That will plot everything in a single step.