Azzera filtri
Azzera filtri

Display axes through origin in Gui

3 visualizzazioni (ultimi 30 giorni)
Nalini
Nalini il 20 Ago 2017
Risposto: Jan il 20 Ago 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 Commento
Jan
Jan il 20 Ago 2017
Please explain "it doesn't seem to work" with any details.

Accedi per commentare.

Risposte (1)

Jan
Jan il 20 Ago 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');

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by