Borrar filtros
Borrar filtros

Display axes through origin in Gui

3 visualizaciones (últimos 30 días)
Nalini
Nalini el 20 de Ag. de 2017
Respondida: Jan el 20 de Ag. de 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 comentario
Jan
Jan el 20 de Ag. de 2017
Please explain "it doesn't seem to work" with any details.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 20 de Ag. de 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');

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by