Effacer les filtres
Effacer les filtres

Display axes through origin in Gui

3 vues (au cours des 30 derniers jours)
Nalini
Nalini le 20 Août 2017
Réponse apportée : Jan le 20 Août 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 commentaire
Jan
Jan le 20 Août 2017
Please explain "it doesn't seem to work" with any details.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 20 Août 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');

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by