Why is the text function so terrible?

The text funtion is absolutely terrible. The only way I can get it to put the text into an axis is to specify the properyvalue 'Parent' during the function call. It is also ridiculously (obscenely) slow. I can plot a 100,000 value dataset in microseconds but plotting an overlay of 30 or 40 2-point annotation lines and text labels takes up to 10 seconds.
Has anybody else built a text function that doesn't suck?

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 11월 9일
>> for K = typecast(uint8('why is the text function so terrible????'),'uint32'); why(K);end
The very good engineer obeyed the tall system manager.
Bill told me to.
Loren suggested it.
The not excessively terrified and not excessively smart and bald bald engineer told me to.
The mathematician knew it was a good idea.
To please a young mathematician.
The bald and rich and smart and tall kid told me to.
The programmer knew it was a good idea.
He knew it was a good idea.
Damian wanted it that way.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2011년 11월 9일

0 개 추천

Dear Alex,
The TEXT function draws to the current AXES object. If you want to add the text to another function, you can either activate the wanted AXES by axes(AxesHandle) or you can specify the 'Parent' property as in all other HG-objects. Thias is consistent and logical. Could you imagine any other reliable method to define where the text should appear?
If your program needs 10 seconds to create the annotations and text labels, this is most likely not a problem of TEXT:
figure;
drawnow;
tic;
for i = 1:40
text(rand, rand, 'asd');
end
drawnow;
toc
>> Elapsed time is 0.025448 seconds
I suggest to use the profiler to find the problem. Another idea would be to post the relevant part of the code in this forum.

댓글 수: 8

Alex
Alex 2011년 11월 9일
It's still slow, but adding the drawnow function after the text statements means it shows up in 0.78 sec instead of hanging for 5-10 sec.
data
Elapsed time is 0.135923 seconds.
annotation
Elapsed time is 0.781526 seconds.
Data is 17225 2-D values being conditioned and displayed. Annotation are 122 points of interest being checked (only about 20 get displayed with a 2-point line and a text label).
text(DATA(NOTE(counter)),YLimits(1),strcat('Label',num2str(counter)),'FontSize', 8,'Color',[ 0 0 0 ],'Parent',handles.axishandle,'Rotation',90,'VerticalAlignment','Top','HorizontalAlignment','Left','Clipping','on');
Jan
Jan 2011년 11월 10일
sprintf('Label%d', counter) would be faster than the STRCAT method. But I do not think, that this is noticable for the small number of calls.
The fact that DRAWNOW has such a large effect seems to imply, that there is a problem with the update of the graphics. Re-drawing 17255 2-D values might consume the most time and TEXT is not to blame.
Alex
Alex 2011년 11월 11일
I first started by drawing all 122 annotations, but as you can imagine, if 20 take 0.8s, then 122 take 4.8s. I added the option to completely ignore the annotation layer -- and it does only take 0.14s. I redraw the entire dataset every time (instead of just the 2000 visible values -- in case I feel like scrolling around) because it doesn't take any time, but I had to filter the annotation to only the visible area JUST TO MAKE IT TOLERABLE. When I just plotted the lines without the text labels, it took some time, but when I added the text labels, the delay time quadrupled.
Sorry, I blame TEXT because everything speeds up dramatically when I remove it.
With TEXT labels:
Elapsed time is 0.402054 seconds.
With TEXT labels commented out:
Elapsed time is 0.066232 seconds.
Jan
Jan 2011년 11월 11일
If you need more assistance, post the code, which takes 0.4 or 0.06 seconds. Currently I do not know, what you are doing. I'm still confused by the term "annotations" - do you mean TEXT-objects or ANNOTATION-objects?
Image Analyst
Image Analyst 2011년 11월 11일
Yes, confusing. Does 122 calls to text() take 0.402054 seconds, or 4.8 seconds? Perhaps if Alex says "I redraw the entire dataset every time" he's calling drawnow inside the loop and that would certainly slow things down as compared to calling it once after the loop.
Daniel Shub
Daniel Shub 2011년 11월 11일
I wonder what DATA(NOTE(counter)) is doing and how long it takes to run.
Michael Richards
Michael Richards 2020년 4월 14일
편집: Michael Richards 2020년 4월 14일
I have encountered a similar problem, and have come to the conclusion that the more text or plot objects that are on the figure, the more memory is taken up.
n = 0.05 % Distance between points
for x = -2:n:2 % horizontal movement
tic(); % start timer
for y = -2:n:2 % vertical movement
plot(x,y,"."); %
end
disp("Average Speed: "+(4/(n*toc()))+" points/s");
end
I use this structure to plot points when the information is conveyed by the colour of the point.
This starts satisfactorily fast, but slows down in an exponential decay.
Here's an example of a program output that uses this:
Mandelbrot
Full screen recommended
Distance between pixels (recommended 0.005): 0.01
Iterations, recommended 15: 9
Enter, or 'abort'
Average speed: 162.1917 points/s
Average speed: 84.7507 points/s
Average speed: 61.7526 points/s
Average speed: 48.826 points/s
Average speed: 41.3745 points/s
Average speed: 36.934 points/s
Average speed: 30.5935 points/s
Average speed: 25.0403 points/s
Average speed: 22.3318 points/s
Average speed: 21.1576 points/s
Average speed: 18.9941 points/s
Walter Roberson
Walter Roberson 2020년 4월 14일
Yes, if you look in the mathworks blogs in around the R2014b / R2015a time, you will see that they show timing tests. Number of objects does have an effect. And whether it is line objects or scatter objects does have an effect. Also, if you were to use an animatedline() and addpoints() then that would change the timing.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

태그

질문:

2011년 11월 9일

댓글:

2020년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by