invertir ejes con uicontrol en matlab
Publicado por manuel (14 intervenciones) el 09/02/2012 04:30:11
hola, pues mi duda es en como hacer que en una interfaz con una grafica poder invertir los ejes con un pop-up menu atraves de uicontrol, solo me falta eso aqui les dejo el codigo completo la funcion que me interesa es la de menu que es el pop-up y pues tambien si me pueden decir como hacer para los valores que introdusca para el eje x sean exactos por ejemplo si introdusco 14 18 19, que solo salgan esos valores en el eje x y no intervalos como me aparece actualmente, pero lo principal es poder invertir los ejes con uicontrol ,espero y se entienda mi idea y me puedan ayudar y pues cualquier cosas estare atento,aqui el codigo:
function varargout = vs(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @vs_OpeningFcn, ...
'gui_OutputFcn', @vs_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function vs_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to vs (see VARARGIN)
% Choose default command line output for vs
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = vs_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
title('Gráfica');
axes(handles.axes);
cla;
valor=get(handles.txt, 'string');
valor=str2num(valor);
valor2=get(handles.txt2, 'string');
valor2=str2num(valor2);
plot(valor,valor2,'-m');
xlim([min(valor) max(valor)]);
ylim([min(valor2) max(valor2)]);
xlabel('centigrados');
ylabel('voltaje');
title('Gráfica sensor');
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject handle to FileMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to OpenMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to PrintMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to CloseMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --- Executes on selection change in p1.
function p1_Callback(hObject, eventdata, handles)
% hObject handle to p1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns p1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from p1
% --- Executes during object creation, after setting all properties.
function p1_CreateFcn(hObject, eventdata, handles)
% hObject handle to p1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function txt_Callback(hObject, eventdata, handles)
% hObject handle to txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txt as text
% str2double(get(hObject,'String')) returns contents of txt as a double
% --- Executes during object creation, after setting all properties.
function txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txt2_Callback(hObject, eventdata, handles)
% hObject handle to txt2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txt2 as text
% str2double(get(hObject,'String')) returns contents of txt2 as a double
% --- Executes during object creation, after setting all properties.
function txt2_CreateFcn(hObject, eventdata, handles)
% hObject handle to txt2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txt3_Callback(hObject, eventdata, handles)
% hObject handle to txt3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txt3 as text
% str2double(get(hObject,'String')) returns contents of txt3 as a double
% --- Executes during object creation, after setting all properties.
function txt3_CreateFcn(hObject, eventdata, handles)
% hObject handle to txt3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in menu.
function menu_Callback(hObject, eventdata, handles)
% hObject handle to menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%=get(handles.valor,'value');
%set(handles.axis,'string',v);
%switch v
%case 1
%plot(valor,valor2,'-m');
%case 2
% plot(valor2,valor,'-b');
%fun =get(handles.sel,'string');
%switch fun
%case 1
%y1=sin(2*pi*1*handles.ejex);
%plot(handles.ejex,y1,'LineWidth',2);grid on;axis([0 2*pi -1 1]);
%case 2
%y2=cos(2*pi*1*handles.ejex);
%plot(handles.ejex,y2,'LineWidth',2);grid on;axis([0 2*pi -1 1]);
%case 3
%y3=sin(2*pi*1*handles.ejex)+cos(2*pi*1*handles.ejex);
%plot(handles.ejex,y3,'LineWidth',2);grid on;
%axis([0 2*pi min(y3) max(y3) ]);
%end
guidata(hObject, handles);
% Hints: contents = get(hObject,'String') returns menu contents as cell array
% contents{get(hObject,'Value')} returns selected item from menu
% --- Executes during object creation, after setting all properties.
function menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function varargout = vs(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @vs_OpeningFcn, ...
'gui_OutputFcn', @vs_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function vs_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to vs (see VARARGIN)
% Choose default command line output for vs
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = vs_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
title('Gráfica');
axes(handles.axes);
cla;
valor=get(handles.txt, 'string');
valor=str2num(valor);
valor2=get(handles.txt2, 'string');
valor2=str2num(valor2);
plot(valor,valor2,'-m');
xlim([min(valor) max(valor)]);
ylim([min(valor2) max(valor2)]);
xlabel('centigrados');
ylabel('voltaje');
title('Gráfica sensor');
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject handle to FileMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to OpenMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to PrintMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to CloseMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --- Executes on selection change in p1.
function p1_Callback(hObject, eventdata, handles)
% hObject handle to p1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns p1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from p1
% --- Executes during object creation, after setting all properties.
function p1_CreateFcn(hObject, eventdata, handles)
% hObject handle to p1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function txt_Callback(hObject, eventdata, handles)
% hObject handle to txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txt as text
% str2double(get(hObject,'String')) returns contents of txt as a double
% --- Executes during object creation, after setting all properties.
function txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txt2_Callback(hObject, eventdata, handles)
% hObject handle to txt2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txt2 as text
% str2double(get(hObject,'String')) returns contents of txt2 as a double
% --- Executes during object creation, after setting all properties.
function txt2_CreateFcn(hObject, eventdata, handles)
% hObject handle to txt2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txt3_Callback(hObject, eventdata, handles)
% hObject handle to txt3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txt3 as text
% str2double(get(hObject,'String')) returns contents of txt3 as a double
% --- Executes during object creation, after setting all properties.
function txt3_CreateFcn(hObject, eventdata, handles)
% hObject handle to txt3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in menu.
function menu_Callback(hObject, eventdata, handles)
% hObject handle to menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%=get(handles.valor,'value');
%set(handles.axis,'string',v);
%switch v
%case 1
%plot(valor,valor2,'-m');
%case 2
% plot(valor2,valor,'-b');
%fun =get(handles.sel,'string');
%switch fun
%case 1
%y1=sin(2*pi*1*handles.ejex);
%plot(handles.ejex,y1,'LineWidth',2);grid on;axis([0 2*pi -1 1]);
%case 2
%y2=cos(2*pi*1*handles.ejex);
%plot(handles.ejex,y2,'LineWidth',2);grid on;axis([0 2*pi -1 1]);
%case 3
%y3=sin(2*pi*1*handles.ejex)+cos(2*pi*1*handles.ejex);
%plot(handles.ejex,y3,'LineWidth',2);grid on;
%axis([0 2*pi min(y3) max(y3) ]);
%end
guidata(hObject, handles);
% Hints: contents = get(hObject,'String') returns menu contents as cell array
% contents{get(hObject,'Value')} returns selected item from menu
% --- Executes during object creation, after setting all properties.
function menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Valora esta pregunta
0