2 questions regarding text() function in a FOR loop for a CURRENT graph.How to define CURRENT graph?
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi guys I have big difficulty adding text to a figure in a FOR LOOP in my function. when the execution of my function is finished;figure (100) is opened, and i use the same below FOR LOOP and it works out and prints out numbers (variable k) in those specific locations.but when I add the same FOR loop in my function, it doesn't print out any thing. Any help would be really appreciated. here is my function:
function [ ]=par1()
figure(100);
plot([2;3;4],[1;0;5]); // the first graph
hold on
plot([0;1;3],[6;4;7],'Color','c'); //the second graph
for k=1:+1:10
figure(100);
text(k,0.5,num2str(k));
drawnow;
end //end of for Loop
end //end of Function
I tried replacing line 7 (figure(100)) outside the For loop , but it didn't work out then I removed line 9, but it doesn't change anything either.
My other question is in the same regard. I wanted to change the XTickLabel of figure(100) to other values in my same function.So i added this line after line 10 (end of for Loop)
set(gca,'XTickLabel',[0:+60:240])
it doesn't work. but if i run these lines after executing my function, it works perfectly fine(meaning the k values appear in my figure). so it seems to me that in both problems, I don't correctly state to the program which figure is the CURRENT one or which AXE is the current Axe. but How can i tell it to my function.
댓글 수: 3
답변 (1개)
Matt Tearle
2012년 9월 12일
I'm having difficulty finding the problem. This works when I run it. Are you not seeing any numbers on your graph? (You won't see all of them because some are outside the current axis limits and text doesn't resize the axes. That much is expected behavior.)
Either way, I think the best answer to your question "How can i tell [which figure is the CURRENT one] to my function" is to keep the handles to graphics objects and use them, in conjunction with the Parent property:
hfg = figure(100);
hax = axes('Parent',hfg);
% do stuff
text(...,'Parent',hax)
% do more stuff
set(hax,'XTickLabel',...)
% etc
plot(hax,...) % plots directly into the specified axes
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!