I've written a brief function to assign a quartile value to a number within any vector of numerical values (matrices are handled as column vectors). It is as follows:
function matrix = movQuantile( TS ) % Organizes a time series into an anchored Quartile
num_col = size(TS,2);
%define output dimensions matrix = NaN(length(TS),num_col);
for j = 1:num_col
for i = 1 :length(TS) %Create a times series of from 1 to i, to create an anchored quartile
metric temp =TS(1:i,j); Q2=median(temp); Q1 = median(temp(temp<Q2)); Q3 = median(temp(temp>Q2)); if TS(i,j)< Q1 x=1; elseif TS(i,j) <Q2 x=2; elseif TS(i,j) < Q3 x=3; else x=4; end matrix (i,j) = x; end
end
end
My question is: is there a way to avoid the secondary loop from 1:length(TS) by using a matrix calculation? The program is slower than I'd like it to be, and this is the most intensive calculation point (especially since temp is getting longer with each iteration of i).
I'm somewhat new to matlab programming, so any help to increase processing time would be appreciated!
Thanks!
Jason
Best Answer