Odpovedať 
 
Hodnotenie témy:
  • 0 Hlasov - 0 Priemer
  • 1
  • 2
  • 3
  • 4
  • 5
Popup menu
04-02-2016, 15:12
Príspevok: #1
Popup menu
Zdravím, v GUI matlabu dělám aplikaci převodu jednotek. Pomocí pop menu1 vybírám jednotky mezi mW,W,kW,MW a pomocí pop menu2 s,ms,us,ns,ps,fs. Při výběru danné jednotky například mW se mi do proměnné x uloží hodnota 1000 a při výběru ns se uloží y=1000000000. Těmato proměnnýma bych pak chtěl vynásobit v rovnici
energie = (x * handles.metricdata.vykon) * (y * handles.metricdata.sirkapulsu);
čísla zadané uživatel(vykon,sirkapulsu) a pak dostat výsledek, nějak mi to ale nechce fungovat.

Nevíte někdo prosím co s tím ? V příloze zasílám i fotku aplikace.

Děkuji moc

Zasílám celý kód aplikace:
function varargout = prazdne(varargin)
% PRAZDNE MATLAB code for prazdne.fig
% PRAZDNE, by itself, creates a new PRAZDNE or raises the existing
% singleton*.
%
% H = PRAZDNE returns the handle to a new PRAZDNE or the handle to
% the existing singleton*.
%
% PRAZDNE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRAZDNE.M with the given input arguments.
%
% PRAZDNE('Property','Value',...) creates a new PRAZDNE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before prazdne_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to prazdne_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 prazdne

% Last Modified by GUIDE v2.5 02-Apr-2016 13:16:21

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

function prazdne_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 prazdne (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

initialize_gui(hObject, handles, false);

function varargout = prazdne_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;


function vykon_Callback(hObject, eventdata, handles)
vykon = str2double(get(hObject, 'String'));
if isnan(vykon)
set(hObject, 'String', 0);
errordlg('Zadejte cislo','Chyba');
end
handles.metricdata.vykon = vykon;
guidata(hObject,handles)

function vykontext_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


function sirkapulsu_Callback(hObject, eventdata, handles)
sirkapulsu = str2double(get(hObject, 'String'));
if isnan(sirkapulsu)
set(hObject, 'String', 0);
errordlg('Zadejte cislo','Chyba');
end
handles.metricdata.sirkapulsu = sirkapulsu;
guidata(hObject,handles)

function sirkapulsutext_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


function rollmenu1_Callback(hObject, eventdata, handles)
contents1 = cellstr(get(hObject,'String'));
popChoice = contents1(get(hObject,'Value'));
if (strcmp(popChoice,'mW'))
rollmenu1 = 1000;
elseif (strcmp(popChoice,'W'))
rollmenu1 = 1;
elseif (strcmp(popChoice,'kW'))
rollmenu1 = 0.001;
elseif (strcmp(popChoice,'MW'))
rollmenu1 = 0.000001;
end
assignin('base','x',rollmenu1);


function rollmenu1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end



function rollmenu2_Callback(hObject, eventdata, handles)
contents2 = cellstr(get(hObject,'String'));
popChoice = contents2(get(hObject,'Value'));
if (strcmp(popChoice,'s'))
rollmenu2 = 1;
elseif (strcmp(popChoice,'ms'))
rollmenu2 = 1000;
elseif (strcmp(popChoice,'µs'))
rollmenu2 = 1000000;
elseif (strcmp(popChoice,'ns'))
rollmenu2 = 1000000000;
elseif (strcmp(popChoice,'ps'))
rollmenu2 = 1000000000000;
elseif (strcmp(popChoice,'fs'))
rollmenu2 = 1000000000000000;
end
assignin('base','y',rollmenu2);


function rollmenu2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function spocitej_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)
energie = (x * handles.metricdata.vykon) * (y * handles.metricdata.sirkapulsu);
set(handles.energie, 'String', energie);


function reset_Callback(hObject, eventdata, handles)
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

initialize_gui(gcbf, handles, true);


function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
if isfield(handles, 'metricdata') && ~isreset
return;
end

set(handles.rollmenu1,'Value',2);
set(handles.rollmenu2,'Value',1);
handles.metricdata.vykon = 0;
handles.metricdata.sirkapulsu = 0;

set(handles.vykon, 'String', handles.metricdata.vykon);
set(handles.sirkapulsu, 'String', handles.metricdata.sirkapulsu);
set(handles.energie, 'String', 0);

% Update handles structure
guidata(handles.figure1, handles);


Priložené súbory Miniatúry
   
Vyhľadať všetky príspevky tohoto používateľa
Citovať príspevok v odpovedi
Odpovedať 


Príspevky v tejto téme
Popup menu - fedkor - 04-02-2016 15:12
RE: Popup menu - Eduard - 04-02-2016, 19:14
RE: Popup menu - fedkor - 04-03-2016, 10:20

Skok na fórum:




Kontakty | matlab.sk | Nahor | Na obsah | Odľahčený (archivačný) mód | RSS