Filter löschen
Filter löschen

Display axes through origin in Gui

3 Ansichten (letzte 30 Tage)
Nalini
Nalini am 20 Aug. 2017
Beantwortet: Jan am 20 Aug. 2017
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 Kommentar
Jan
Jan am 20 Aug. 2017
Please explain "it doesn't seem to work" with any details.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 20 Aug. 2017
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');

Kategorien

Mehr zu Two y-axis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by