ich habe ein Performanceproblem welches ich mit dem Profiler lokalisiert habe.
Code:
for j=1:size(obj.mAVG_Indicator,1) if obj.mAVG_Indicator(j,1)==0
x=libpointer('doublePtr',obj.Performance(:,obj.mAVG_Indicator(j,2)));
else
x=libpointer('doublePtr',obj.ts(:,obj.mAVG_Indicator(j,2)));
end
obj.mAVG=[obj.mAVG,zeros(size(x.value,1),1)];%Expand the matrix
for i=1:size(x.value,1)-obj.mAVG_Indicator(j,3)+1-TSDelay(j) for k=1:obj.mAVG_Indicator(j,3)
obj.mAVG(i,j+1)=obj.mAVG(i,j+1)+x.value(i+k-1);
end end
obj.mAVG(:,j+1)=obj.mAVG(:,j+1)/obj.mAVG_Indicator(j,3);
for i=i+1:size(x.value,1)
obj.mAVG(i,j+1)=NaN;
end end
danke für den Hinweis! An der Stelle werden rollierende Summen gebildet, welche mit sum wahrscheinlich schneller laufen werden.
Ich prüfe mal mit dem Profiler welchen Vorteil das bringt.
Es ist schwierig und fehleranfällig, sich aus mehreren Postings die korrekte Funktion zusammen zu kopieren, um sie verbessern zu können. Dies schein ein Moving Average zu sein:
DANKE, ich habe die Idee mit dem Filter umgesetzt:
Code:
function CalcMovingAVG(obj)
bCalcPerformanceYesNo=Boolean.No;
TSDelay=zeros(size(obj.mAVG_Indicator,1),1);
%Example: TS starts on 11/23/1990 -> Performace is available
%from 11/26/1990 onwards. If Moving AVG is based on Performace
%there will be a delay of 1day -> TSDelay=1 for j=1:size(obj.mAVG_Indicator,1) if obj.mAVG_Indicator(j,1)==0
bCalcPerformanceYesNo=Boolean.Yes;
TSDelay(j)=1;
end end if bCalcPerformanceYesNo
CalcPerformance(obj);
end
obj.mAVG=[obj.ts(:,1),NaN(size(obj.ts(:,1),1),size(obj.mAVG_Indicator,1))];
for j=1:size(obj.mAVG_Indicator,1)
b=ones(1,obj.mAVG_Indicator(j,3))/obj.mAVG_Indicator(j,3);
if obj.mAVG_Indicator(j,1)==0
x=libpointer('doublePtr',obj.Performance(:,obj.mAVG_Indicator(j,2)));
else
x=libpointer('doublePtr',obj.ts(:,obj.mAVG_Indicator(j,2)));
end
obj.mAVG(1:size(x.value,1)-TSDelay(j),j+1) = filter(b,1,flipud(x.value(1:size(x.value,1)-TSDelay(j))));
obj.mAVG(1:size(x.value,1)-TSDelay(j),j+1)=flipud(obj.mAVG(1:size(x.value,1)-TSDelay(j),j+1));
obj.mAVG(size(x.value,1)-obj.mAVG_Indicator(j,3)+2-TSDelay(j):size(x.value,1),j+1)=NaN;
end end
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.