plot figure in gui guide, to axes
古いコメントを表示
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 件のコメント
Ankit
2020 年 2 月 26 日
how you code for plotting looks like?
polo Mahmoud
2020 年 2 月 26 日
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 日
polo Mahmoud
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 日
polo Mahmoud
2020 年 2 月 26 日
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 日
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 日
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.
polo Mahmoud
2020 年 2 月 27 日
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.
polo Mahmoud
2020 年 2 月 27 日
polo Mahmoud
2020 年 2 月 27 日
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.
polo Mahmoud
2020 年 2 月 28 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!