フィルターのクリア

Display axes through origin in Gui

3 ビュー (過去 30 日間)
Nalini
Nalini 2017 年 8 月 20 日
回答済み: Jan 2017 年 8 月 20 日
I want to plot the axes inside the box through origin in the Gui.. Not outside the box. I have tried the following, but it doesn't seem to work. Any suggestions would be very helpful!!! Thank you!
function solve_Callback(hObject, eventdata, handles)
% hObject handle to solve (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = str2num(get(handles.a,'string'));
b = str2num(get(handles.b,'string'));
c = str2num(get(handles.c,'string'));
y = num2str(c/b);
s = num2str(-a/b);
set(handles.intercept,'string',y);
set(handles.slope,'string',s);
x = -10:1:10;
y = (c/b) - ((a/b)*x);
axes(handles.axes1)
ax = plot(x,y)
grid on
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel('x'); ylabel('y');
guidata(hObject,handles)
%
  1 件のコメント
Jan
Jan 2017 年 8 月 20 日
Please explain "it doesn't seem to work" with any details.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2017 年 8 月 20 日
Do not set the axis-location of the plotted line object, but of the axes:
axes(handles.axes1)
plot(x,y)
grid on
handles.axes1.XAxisLocation = 'origin';
handles.axes1.YAxisLocation = 'origin';
It would be save not to rely on the current axes, but to set the 'Parent' property directly:
ax = handles.axes1;
plot(ax, x,y);
grid(ax, 'on');
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel(ax, 'x');
ylabel(ax, 'y');

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by