MATLAB GUI 可执行文件 windows 应用程序无法显示
MATLAB GUI executable windows application wont display
我在 MATLAB 中创建了一个图像识别应用程序,它加载图像然后检测它是什么货币。在 MATLAB 上,我已经 运行 运行了数千次带有 GUI 显示的程序,并且在 MATLAB 环境中一切正常。
但是当我通过 MATLAB 将项目转换为可执行文件时,GUI 根本不会显示,但它仍然会 运行 在后台,所以我必须去任务管理器手动关闭程序。我已经为我的电脑安装了 MATLAB Runtime。
我做了一个测试并创建了一个只有一个按钮的简单 GUI,将其转换为可执行文件并且 运行 可以很好地显示 GUI 的内容。所以我知道 MATLAB 没有任何问题,它只是我的代码。
所以我 运行 通过命令 window 执行图像识别并得到这个错误。
java.lang.IllegalStateException: ActionData AbstractNamedUniqueID object with unique ID 'close-genome-desktop' and user-visible name 'Exit NGS Browser'. is already registered.
at com.mathworks.mwswing.binding.KeyBindingManager.throwError(KeyBindingManager.java:623)
at com.mathworks.mwswing.binding.KeyBindingManager.addAction(KeyBindingManager.java:201)
at com.mathworks.mwswing.binding.KeyBindingManager.parseAndRegisterActions(KeyBindingManager.java:71)
at com.mathworks.services.binding.MatlabKeyBindings.addActionFile(MatlabKeyBindings.java:666)
at com.mathworks.services.binding.MatlabKeyBindings.readActionAndContextFilesFromOSGi(MatlabKeyBindings.java:639)
at com.mathworks.services.binding.MatlabKeyBindings.<clinit>(MatlabKeyBindings.java:592)
at com.mathworks.widgets.action.BaseAbstractAction.<init>(BaseAbstractAction.java:24)
at com.mathworks.widgets.action.AbstractNewAction.<init>(AbstractNewAction.java:24)
at com.mathworks.hg.peer.FiguresGroup$NewFigureAction.<init>(FiguresGroup.java:78)
at com.mathworks.hg.peer.FiguresGroup.createToolBar(FiguresGroup.java:68)
at com.mathworks.hg.peer.FiguresGroup.<init>(FiguresGroup.java:43)
at com.mathworks.hg.peer.FiguresGroup.getInstance(FiguresGroup.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.widgets.desk.DTGroup.createPropertyProvider(DTGroup.java:253)
at com.mathworks.widgets.desk.DTGroup.getPropertyProvider(DTGroup.java:190)
at com.mathworks.widgets.desk.DTOccupant.getProperty(DTOccupant.java:748)
at com.mathworks.widgets.desk.DTOccupant.getToolstripTabs(DTOccupant.java:520)
at com.mathworks.widgets.desk.DTGroup.add(DTGroup.java:345)
at com.mathworks.widgets.desk.Desktop.addClient(Desktop.java:6569)
at com.mathworks.widgets.desk.Desktop.addClient(Desktop.java:6536)
at com.mathworks.widgets.desk.Desktop.addSingletons(Desktop.java:5603)
at com.mathworks.mde.desk.MLDesktop.<init>(MLDesktop.java:554)
at com.mathworks.mde.desk.MLDesktop.getInstance(MLDesktop.java:615)
at com.mathworks.mde.desk.MLDesktopRegistrar.getDesktop(MLDesktopRegistrar.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.mlservices.MLServices.getRegisteredService(MLServices.java:29)
at com.mathworks.mlservices.MatlabDesktopServices.<clinit>(MatlabDesktopServices.java:14)
at com.mathworks.hg.peer.FigureClientProxy.getMatlabDesktop(FigureClientProxy.java:504)
at com.mathworks.hg.peer.FigureClientProxy.<init>(FigureClientProxy.java:92)
at com.mathworks.hg.peer.HG2FigureClientProxy.<init>(HG2FigureClientProxy.java:20)
at com.mathworks.hg.peer.FigureHG2Mediator.<init>(FigureHG2Mediator.java:43)
at com.mathworks.hg.peer.HG2FigurePeer.createFigureClient(HG2FigurePeer.java:74)
at com.mathworks.hg.peer.FigurePeer.doInitializePeer(FigurePeer.java:454)
at com.mathworks.hg.peer.FigurePeer.run(FigurePeer.java:419)
at com.mathworks.jmi.AWTUtilities$Invoker.run(AWTUtilities.java:591)
at com.mathworks.mvm.context.ThreadContext.call(ThreadContext.java:76)
at com.mathworks.mvm.context.ThreadContext.callWithContext(ThreadContext.java:105)
at com.mathworks.mvm.context.ThreadContext.runWithContext(ThreadContext.java:73)
at com.mathworks.mvm.context.MvmContext.runWithContext(MvmContext.java:107)
at com.mathworks.jmi.AWTUtilities$Invoker.runWithOutput(AWTUtilities.java:588)
at com.mathworks.jmi.AWTUtilities$Invoker.watchedRun(AWTUtilities.java:475)
at com.mathworks.jmi.AWTUtilities$WatchedRunnable.run(AWTUtilities.java:436)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Warning: Unable to create com.mathworks.hg.peer.FiguresGroup, for details see
C:\Users\ELECTR~1\AppData\Local\Temp\MATLABDesktopCreateError.log
这是我的主文件,它调用我的所有函数并具有 GUI 事件操作 - Image.m
function varargout = Image(varargin)
% IMAGE MATLAB code for Image.fig
% IMAGE, by itself, creates a new IMAGE or raises the existing
% singleton*.
%
% H = IMAGE returns the handle to a new IMAGE or the handle to
% the existing singleton*.
%
% IMAGE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE.M with the given input arguments.
%
% IMAGE('Property','Value',...) creates a new IMAGE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Image_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Image_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 Image
% Last Modified by GUIDE v2.5 14-May-2016 19:14:58
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Image_OpeningFcn, ...
'gui_OutputFcn', @Image_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 Image is made visible.
function Image_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 Image (see VARARGIN)
% Choose default command line output for Image
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Image wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Image_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)
global im im2
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1);
imshow(im);
currency = ClassImages(path)
set(handles.edit1,'String',currency)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 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)
global im im2 %Hold two images im-Main-Image im2-Second-Image
[path,user_cance]=imgetfile(); % Push button and store the path of the image in path
if user_cance
msgbox(sprintf('Error'),'Error','Error'); % If Image is not found display error
return
end
im=imread(path); %Read image and store in im
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1); % Display the image on the axes
imshow(im); %Show Image
currency = ClassImages(path) % Stores the currency of the image in currency
set(handles.edit1,'String',currency) %Sets edit box in the GUI to the value of the currency
我不知道出了什么问题,运行在 MATLAB 中运行时它工作正常,但当它成为可执行应用程序时崩溃。
是的,我能够解决它。最初我使用的是 MATLAB R2016a。我使用的是一个旧函数,MATLAB 警告说它会在下一组 MATLAB 应用程序中被淘汰。当我删除旧函数并将其重新编译成可执行文件时,它就可以工作了。因此,最初 R2016a 的 MATLAB 运行时在其库中没有该函数。但是我需要该功能才能使我的应用程序正常工作。所以我降级到 MATLAB R2015a,我的可执行文件使用包含的旧函数。
我在 MATLAB 中创建了一个图像识别应用程序,它加载图像然后检测它是什么货币。在 MATLAB 上,我已经 运行 运行了数千次带有 GUI 显示的程序,并且在 MATLAB 环境中一切正常。
但是当我通过 MATLAB 将项目转换为可执行文件时,GUI 根本不会显示,但它仍然会 运行 在后台,所以我必须去任务管理器手动关闭程序。我已经为我的电脑安装了 MATLAB Runtime。
我做了一个测试并创建了一个只有一个按钮的简单 GUI,将其转换为可执行文件并且 运行 可以很好地显示 GUI 的内容。所以我知道 MATLAB 没有任何问题,它只是我的代码。
所以我 运行 通过命令 window 执行图像识别并得到这个错误。
java.lang.IllegalStateException: ActionData AbstractNamedUniqueID object with unique ID 'close-genome-desktop' and user-visible name 'Exit NGS Browser'. is already registered.
at com.mathworks.mwswing.binding.KeyBindingManager.throwError(KeyBindingManager.java:623)
at com.mathworks.mwswing.binding.KeyBindingManager.addAction(KeyBindingManager.java:201)
at com.mathworks.mwswing.binding.KeyBindingManager.parseAndRegisterActions(KeyBindingManager.java:71)
at com.mathworks.services.binding.MatlabKeyBindings.addActionFile(MatlabKeyBindings.java:666)
at com.mathworks.services.binding.MatlabKeyBindings.readActionAndContextFilesFromOSGi(MatlabKeyBindings.java:639)
at com.mathworks.services.binding.MatlabKeyBindings.<clinit>(MatlabKeyBindings.java:592)
at com.mathworks.widgets.action.BaseAbstractAction.<init>(BaseAbstractAction.java:24)
at com.mathworks.widgets.action.AbstractNewAction.<init>(AbstractNewAction.java:24)
at com.mathworks.hg.peer.FiguresGroup$NewFigureAction.<init>(FiguresGroup.java:78)
at com.mathworks.hg.peer.FiguresGroup.createToolBar(FiguresGroup.java:68)
at com.mathworks.hg.peer.FiguresGroup.<init>(FiguresGroup.java:43)
at com.mathworks.hg.peer.FiguresGroup.getInstance(FiguresGroup.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.widgets.desk.DTGroup.createPropertyProvider(DTGroup.java:253)
at com.mathworks.widgets.desk.DTGroup.getPropertyProvider(DTGroup.java:190)
at com.mathworks.widgets.desk.DTOccupant.getProperty(DTOccupant.java:748)
at com.mathworks.widgets.desk.DTOccupant.getToolstripTabs(DTOccupant.java:520)
at com.mathworks.widgets.desk.DTGroup.add(DTGroup.java:345)
at com.mathworks.widgets.desk.Desktop.addClient(Desktop.java:6569)
at com.mathworks.widgets.desk.Desktop.addClient(Desktop.java:6536)
at com.mathworks.widgets.desk.Desktop.addSingletons(Desktop.java:5603)
at com.mathworks.mde.desk.MLDesktop.<init>(MLDesktop.java:554)
at com.mathworks.mde.desk.MLDesktop.getInstance(MLDesktop.java:615)
at com.mathworks.mde.desk.MLDesktopRegistrar.getDesktop(MLDesktopRegistrar.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.mlservices.MLServices.getRegisteredService(MLServices.java:29)
at com.mathworks.mlservices.MatlabDesktopServices.<clinit>(MatlabDesktopServices.java:14)
at com.mathworks.hg.peer.FigureClientProxy.getMatlabDesktop(FigureClientProxy.java:504)
at com.mathworks.hg.peer.FigureClientProxy.<init>(FigureClientProxy.java:92)
at com.mathworks.hg.peer.HG2FigureClientProxy.<init>(HG2FigureClientProxy.java:20)
at com.mathworks.hg.peer.FigureHG2Mediator.<init>(FigureHG2Mediator.java:43)
at com.mathworks.hg.peer.HG2FigurePeer.createFigureClient(HG2FigurePeer.java:74)
at com.mathworks.hg.peer.FigurePeer.doInitializePeer(FigurePeer.java:454)
at com.mathworks.hg.peer.FigurePeer.run(FigurePeer.java:419)
at com.mathworks.jmi.AWTUtilities$Invoker.run(AWTUtilities.java:591)
at com.mathworks.mvm.context.ThreadContext.call(ThreadContext.java:76)
at com.mathworks.mvm.context.ThreadContext.callWithContext(ThreadContext.java:105)
at com.mathworks.mvm.context.ThreadContext.runWithContext(ThreadContext.java:73)
at com.mathworks.mvm.context.MvmContext.runWithContext(MvmContext.java:107)
at com.mathworks.jmi.AWTUtilities$Invoker.runWithOutput(AWTUtilities.java:588)
at com.mathworks.jmi.AWTUtilities$Invoker.watchedRun(AWTUtilities.java:475)
at com.mathworks.jmi.AWTUtilities$WatchedRunnable.run(AWTUtilities.java:436)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Warning: Unable to create com.mathworks.hg.peer.FiguresGroup, for details see
C:\Users\ELECTR~1\AppData\Local\Temp\MATLABDesktopCreateError.log
这是我的主文件,它调用我的所有函数并具有 GUI 事件操作 - Image.m
function varargout = Image(varargin)
% IMAGE MATLAB code for Image.fig
% IMAGE, by itself, creates a new IMAGE or raises the existing
% singleton*.
%
% H = IMAGE returns the handle to a new IMAGE or the handle to
% the existing singleton*.
%
% IMAGE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE.M with the given input arguments.
%
% IMAGE('Property','Value',...) creates a new IMAGE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Image_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Image_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 Image
% Last Modified by GUIDE v2.5 14-May-2016 19:14:58
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Image_OpeningFcn, ...
'gui_OutputFcn', @Image_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 Image is made visible.
function Image_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 Image (see VARARGIN)
% Choose default command line output for Image
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Image wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Image_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)
global im im2
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1);
imshow(im);
currency = ClassImages(path)
set(handles.edit1,'String',currency)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 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)
global im im2 %Hold two images im-Main-Image im2-Second-Image
[path,user_cance]=imgetfile(); % Push button and store the path of the image in path
if user_cance
msgbox(sprintf('Error'),'Error','Error'); % If Image is not found display error
return
end
im=imread(path); %Read image and store in im
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1); % Display the image on the axes
imshow(im); %Show Image
currency = ClassImages(path) % Stores the currency of the image in currency
set(handles.edit1,'String',currency) %Sets edit box in the GUI to the value of the currency
我不知道出了什么问题,运行在 MATLAB 中运行时它工作正常,但当它成为可执行应用程序时崩溃。
是的,我能够解决它。最初我使用的是 MATLAB R2016a。我使用的是一个旧函数,MATLAB 警告说它会在下一组 MATLAB 应用程序中被淘汰。当我删除旧函数并将其重新编译成可执行文件时,它就可以工作了。因此,最初 R2016a 的 MATLAB 运行时在其库中没有该函数。但是我需要该功能才能使我的应用程序正常工作。所以我降级到 MATLAB R2015a,我的可执行文件使用包含的旧函数。