필터 지우기
필터 지우기

text() error. Any work around ?

조회 수: 5 (최근 30일)
Scott Urquhart
Scott Urquhart 2015년 11월 13일
댓글: Walter Roberson 2015년 11월 14일
Hello,
I am encountering what I think is a bug.
figure(1)
plot(1:10,1:10)
MapEfieldTxt=text([3,6],[3,6],{'Name1','Name2'});
pos2=get(MapEfieldTxt,'Position');
str2=get(MapEfieldTxt,'String');
set(MapEfieldTxt,'Position',pos2,'String',str2)
This return :
Error using matlab.graphics.primitive.Text/set
While setting the 'Position' property of 'Text':
Value must be a 2 or 3 element vector of numeric or logical type
I get the 'Position' and the 'String' from the handle and set it back right after it without modification and it return this error. There is something wrong in the output/input format.
Does anyone knows a work around ?
Thanks
  댓글 수: 2
Stephen23
Stephen23 2015년 11월 14일
What MATLAB version are you using?
Scott Urquhart
Scott Urquhart 2015년 11월 14일
2015b

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

답변 (2개)

Image Analyst
Image Analyst 2015년 11월 14일
I don't know why you're doing all that weird complicated stuff when it looks like you simply want to place two text strings on the plot. So simply use text() the way the vast majority of MATLAB users do:
text(3, 3, 'Name1');
text(6, 6, 'Name2');
  댓글 수: 2
Scott Urquhart
Scott Urquhart 2015년 11월 14일
I have more than hundreds Name to display.
Image Analyst
Image Analyst 2015년 11월 14일
So what? Though your plot might get very cluttered. text() can be called hundreds of times, or once inside a loop. It can even be called with a variable as the third, text string argument. For example
for k = 1 : 200
x = k;
y = 3*k; % whatever....
theLabel = sprintf('Name%d', k);
text(x, y, theLabel);
end

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


Walter Roberson
Walter Roberson 2015년 11월 14일
At least in R2014a, when you pass multiple coordinates to text(), you get back a vector of handles, not a single handle.
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 11월 14일
Because you are getting a vector of handles, when you get() the Position property of the vector of handles you are going to get a cell array. You then try to set() the Position property of the vector of handles to that cell array, which is not permitted. You will need to loop setting the location and string property per-handle.

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by