2013-03-20 25 views
0

我正在努力如何使用Matlab gui界面。Matlab GUI,使用靜態文本框的輸入並將其轉換爲基本按鈕

我不是在尋找答案,只是一些更多的指導如何做到這一點。

我想將編輯框中的溫度從F轉換爲C ...所以我想我需要方程式在按鈕中。

我想我被困在如何從編輯框傳遞數字到按鈕來轉換它,然後如何將它傳回,然後顯示它。 這是否有意義?

function varargout = ICA09A_TEMPFtoC(varargin) 
% ICA09A_TEMPFTOC MATLAB code for ICA09A_TEMPFtoC.fig 
%  ICA09A_TEMPFTOC, by itself, creates a new ICA09A_TEMPFTOC or raises the existing 
%  singleton*. 
% 
%  H = ICA09A_TEMPFTOC returns the handle to a new ICA09A_TEMPFTOC or the handle to 
%  the existing singleton*. 
% 
%  ICA09A_TEMPFTOC('CALLBACK',hObject,eventData,handles,...) calls the local 
%  function named CALLBACK in ICA09A_TEMPFTOC.M with the given input arguments. 
% 
%  ICA09A_TEMPFTOC('Property','Value',...) creates a new ICA09A_TEMPFTOC or raises  the 
%  existing singleton*. Starting from the left, property value pairs are 
%  applied to the GUI before ICA09A_TEMPFtoC_OpeningFcn gets called. An 
%  unrecognized property name or invalid value makes property application 
%  stop. All inputs are passed to ICA09A_TEMPFtoC_OpeningFcn via varargin. 
% 
%  *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 
%  instance to run (singleton)". 
% 
% See also: GUIDE, GUIDATA, GUIHANDLES 

% Edit the above text to modify the response to help ICA09A_TEMPFtoC 

% Last Modified by GUIDE v2.5 20-Mar-2013 13:14:08 

% Begin initialization code - DO NOT EDIT 
gui_Singleton = 1; 
gui_State = struct('gui_Name',  mfilename, ... 
        'gui_Singleton', gui_Singleton, ... 
        'gui_OpeningFcn', @ICA09A_TEMPFtoC_OpeningFcn, ... 
        'gui_OutputFcn', @ICA09A_TEMPFtoC_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 
% End initialization code - DO NOT EDIT 


% --- Executes just before ICA09A_TEMPFtoC is made visible. 
function ICA09A_TEMPFtoC_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 ICA09A_TEMPFtoC (see VARARGIN) 

% Choose default command line output for ICA09A_TEMPFtoC 
handles.output = hObject; 

% Update handles structure 
guidata(hObject, handles); 

% UIWAIT makes ICA09A_TEMPFtoC wait for user response (see UIRESUME) 
% uiwait(handles.figure1); 


% --- Outputs from this function are returned to the command line. 
function varargout = ICA09A_TEMPFtoC_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 convert_pb. 
function convert_pb_Callback(hObject, eventdata, handles) 
% hObject handle to convert_pb (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
InputString = get(handles.convert_pb,'Convert'); 

InputNumber = str2num(InputString); 

Result = (5/9) * (InputNumber - 32); 

set(handles.result, 'Convert', Result); 


function degF_et_Callback(hObject, eventdata, handles) 
% hObject handle to degF_et (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 degF_et as text 
%  str2double(get(hObject,'String')) returns contents of degF_et as a double 
UserInput = str2double(get(hObject,'String')) 

% --- Executes during object creation, after setting all properties. 
function degF_et_CreateFcn(hObject, eventdata, handles) 
% hObject handle to degF_et (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 

有什麼我應該做的,以便讓任何人編輯這個更具可讀性?

+0

你能後你有這麼遠的代碼? – eykanal 2013-03-20 18:39:20

+0

給我一分鐘...工作。 – Liquidmetal 2013-03-20 18:45:08

+0

對不起,任何混亂的行,我總是有麻煩代碼添加到此網站。 – Liquidmetal 2013-03-20 18:50:22

回答

1

要獲得在文本編輯框中輸入使用溫度:

tempF = get(handles.degF_et,'String'); 

這可以從按鈕的功能調用。

要更改顯示有使用的字符串:

set(handles.degF_et,'String','some string'); 
+0

感謝一噸,apppreciate它 – Liquidmetal 2013-03-20 19:34:02

相關問題