이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
plot figure in gui guide, to axes
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
i want to plot a figure to axes in gui guide, but only the legend is showing and the xlim and ylim is not auto, i goes from 0 to 1 ( but should be auto)
댓글 수: 19
polo Mahmoud
2020년 2월 26일
for i=1:length(av(:,1))
% figure
axes(handles.axes13);
plot(t,av(i,:),'k','LineWidth',1.8)
hold on
% figure
plot(t,Acc(VSENS(i),:),'r','LineWidth',0.8)
hold on
% plot(t,zeros(1,length(av(:,1))),'k')
% hold on
% figure
plot(t,ErrorM,'color',[0,0,0]+0.5)
if NX==1
legend('Estimated','Newmark','Error')
elseif NX==2
legend('Estimated','Measured','Error')
end
grid on
set(gca, 'FontName', 'Times New Roman')
set(gca,'FontSize',18)
set(gcf,'color','w');
ylabel('Acceleration [m/s^2]')
xlabel('Time [s]')
title(['ME FreeDOF ',sprintf('%d',MVSENS(i))])
end
Rik
2020년 2월 26일
Did you check with the debugger if one of the legend calls actually runs?
It is also better practice to use explicit parent handles whenever working with a GUI.
%so this:
axes(handles.axes13);
plot(t,av(i,:),'k','LineWidth',1.8)
hold on
plot(t,Acc(VSENS(i),:),'r','LineWidth',0.8)
plot(t,ErrorM,'color',[0,0,0]+0.5)
legend('Estimated','Newmark','Error')
%becomes this:
h_plots=plot(t,av(i,:),'k','LineWidth',1.8,...
'Parent',handles.axes13)
hold(handles.axes13,'on')
h_plots(2)=plot(t,Acc(VSENS(i),:),'r','LineWidth',0.8,...
'Parent',handles.axes13)
h_plots(3)=plot(t,ErrorM,'color',[0,0,0]+0.5,...
'Parent',handles.axes13)
legend(h_plots,'Estimated','Newmark','Error')
%or even better:
h_plots=plot(t,av(i,:),'k','LineWidth',1.8,...
'DisplayName','Estimated',...
'Parent',handles.axes13)
hold(handles.axes13,'on')
h_plots(2)=plot(t,Acc(VSENS(i),:),'r','LineWidth',0.8,...
'DisplayName','Newmark',...
'Parent',handles.axes13)
h_plots(3)=plot(t,ErrorM,'color',[0,0,0]+0.5,...
'DisplayName','Error',...
'Parent',handles.axes13)
legend(h_plots)
polo Mahmoud
2020년 2월 26일
hi rik
is says :
Unable to perform assignment because the left and right sides have a different number of elements.
Error in New_gui_polo_26_02>pushbutton28_Callback (line 2063)
h_plots(2)=plot(t,Acc(VSENS(i),:),'r','LineWidth',0.8,...
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in New_gui_polo_26_02 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)New_gui_polo_26_02('pushbutton28_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Rik
2020년 2월 26일
편집: Rik
2020년 2월 26일
None of the code you show is actually changing the axes limits, so you must have done that somewhere else. And did you check what shape data is being plotted? If it is scalar it will not show up.
That is probably also the cause of the error. If no graphics object is created you will get this error. See the MWE below.
figure(1),clf(1)
h=plot(rand(2,1),rand(2,1));
h(2)=plot([],[]);
polo Mahmoud
2020년 2월 26일
it is vectors that i plot.
and i have checked that both the xlim and ylim is set to auto in gui, but i dont understand
polo Mahmoud
2020년 2월 26일
i tryied the example code :
figure(1),clf(1)
h=plot(rand(2,1),rand(2,1));
h(2)=plot([],[]);
is says : but i plotted a line
Unable to perform assignment because the left and right sides have a different number of elements.
Rik
2020년 2월 26일
Exactly. This is the same way in which your code fails as well. And you can even see that in your legend: only black lines, meaning that no other graphics objects are generated, so there is no valid data in your second and third plot call.
polo Mahmoud
2020년 2월 26일
편집: Rik
2020년 2월 26일
when i evaluated my gui code from matlab, it gives data for all. but when i run it through gui i gives this error
for the first part when i run my gui is says this
Line
Line
Line
Line
[edit Rik: removed the dozens of repetitions that followed]
Rik
2020년 2월 26일
If you get a different result when calling it from your GUI, that means the code is different.
polo Mahmoud
2020년 2월 26일
But I use the function " Evaluate" for the gui .m file it works good
But when i run the gui and uses the "button" to evaluate it gives that error
Rik
2020년 2월 26일
If the input is the same, the output will be as well. You need to make sure that your GUI calls the function with the same input as when you run the function outside of the context of your GUI.
Rik
2020년 2월 27일
I forgot to add in the semicolon, because I wrote the code in this editor, so I didn't have mlint to warn me.
h=plot(rand(4,1)) %no ; so returns an output and will display "Line"
If one call to plot generates multiple objects, it will form a vector, so you will get the result you wrote.
Rik
2020년 2월 27일
As I have said before: you need to make sure the input is the same for the two situations. What is the exact input to your function when you run it indepently, and what is the input when you call it from your GUI? Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue. You can attach files with the paperclip icon if needed.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)