App Designer: Slowdown when using antilog/exponential function
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I have made an app that shows, among other things, an fft plot of some serial data that is received in real-time. It shows this fft as a logarithmic output so the noise floor is actually very high. To resolve this taken the antilog of the output with one line of code:
out = 2.^(out/512);
When I use this line the fft plot looks much better but after a minute the program gets VERY slow. Does anyone have any ideas why? Is there an alternative function to take the antilog of the output without using so much memory?
Cheers, Akash
2 件のコメント
回答 (1 件)
Steven Lord
2016 年 10 月 24 日
If you're calling plot in a loop, and the axes has been held using hold on, each iteration through the loop is adding one (or more) additional lines to the axes. As the number of lines grows, so does the time required to add new ones. Consider:
% Create data
x = 0:5:360;
% Initialize axes
ax = axes;
axis([0 360 -1 1]);
hold(ax, 'on')
% Plot in a loop and display how many lines are present
for k = 1:10
plot(x, sind(k*x));
c = findall(ax, 'Type', 'line');
fprintf('For k = %d, the axes has %d children.\n', k, length(c));
drawnow
end
Consider if you actually need all the lines at once. Compare the above with:
% Create data
x = 0:5:360;
% Initialize axes
ax = axes;
axis([0 360 -1 1]);
hold(ax, 'on')
% Plot one line at a time and display how many lines are present
h = plot(x, NaN(size(x)));
for k = 1:10
h.YData = sind(k*x);
c = findall(ax, 'Type', 'line');
fprintf('For k = %d, the axes has %d children.\n', k, length(c));
pause % so you can see each line
drawnow
end
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!