Huge Execution Time Discrepancy with line() Command

1 回表示 (過去 30 日間)
Eric
Eric 2012 年 1 月 14 日
The following code takes no more than 4 seconds to execute:
figure(statfig);
set(gcf,'Position',get(0,'ScreenSize').*[1 1 0.5 1]);
titlestr = [test ' - Statistics - ' num2str(rpmval) 'RPM - ' samplestr ' - ' upper(sensor)];
subplot(size(detdata,2),1,var);
plot(detdata(:,var)');
hold on;
% line([1:length(detdata)],avg_env_sample(var),'Color','r');
% line([1:length(detdata)],avg_env(var),'Color','g');
hold off;
% legend('Detrended Data','Envelope','Envelope Mean');
title([titlestr ' - ' varname]);
xlabel('Sample [n]');
ylabel([varname ' [g]']);
set(gcf,'Name',titlestr);
With the commented code uncommented, execution time goes up to two minutes. Similar code is executed 3 other times (without the line commands) without a problem.
Any suggestions?
  3 件のコメント
Eric
Eric 2012 年 1 月 14 日
16000
Eric
Eric 2012 年 1 月 14 日
But plot() gets executed on that sized data many (hundreds) of times, with no issues.

サインインしてコメントする。

採用された回答

Rob Graessle
Rob Graessle 2012 年 1 月 14 日
Are you expecting each call to 'line' to draw 15999 lines or just one line? If it is the latter, try this instead:
line([1 length(detdata)],avg_env_sample(var),'Color','r');
line([1 length(detdata)],avg_env(var),'Color','g');
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 14 日
It appears to me that var is a scalar, as otherwise the subplot() would not work. Then in order to draw a horizontal line, the y coordinate would need to be duplicated:
line([1 length(detdata)],avg_env_sample([var var]),'Color','r');
line([1 length(detdata)],avg_env([var var]),'Color','g');
Eric
Eric 2012 年 1 月 14 日
So my understanding is this will draw a horizontal line interpolated from two (x,y) points instead of a 16000 point line? I still don't understand why the execution of the original code is so slow if plot() executes so quickly on the same sized data. But it does bring everything back to normal. Thank you Walter and Rob.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by