XLSREAD returns an error when used in a standalone app

4 views (last 30 days)
Hello,
I've written a simple code which returns an error whilst used in a standalone app (it doesn't return any errors when used in matlab environment. I have a GUI with 1 pushbutton with the code below
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
filename = 'feed.xlsx';
% read data from file
[~, ~, xlsxdata] = xlsread(filename);
assignin('base','xlsxdata',xlsxdata);
Once again, there are no errors when it is run in Matlab. However when I run it as a standalone app, I get an error sound.
Running it through console returns this:
Full code for a function testfig is below:
function varargout = testfig(varargin)
% TESTFIG MATLAB code for testfig.fig
% TESTFIG, by itself, creates a new TESTFIG or raises the existing
% singleton*.
%
% H = TESTFIG returns the handle to a new TESTFIG or the handle to
% the existing singleton*.
%
% TESTFIG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTFIG.M with the given input arguments.
%
% TESTFIG('Property','Value',...) creates a new TESTFIG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before testfig_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to testfig_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 testfig
% Last Modified by GUIDE v2.5 02-Jan-2015 01:24:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testfig_OpeningFcn, ...
'gui_OutputFcn', @testfig_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 testfig is made visible.
function testfig_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 testfig (see VARARGIN)
% Choose default command line output for testfig
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes testfig wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = testfig_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)
filename = 'feed.xlsx';
% read data from file
[~, ~, xlsxdata] = xlsread(filename);
assignin('base','xlsxdata',xlsxdata);
Thank you for your help!
  6 Comments
Alexey
Alexey on 2 Jan 2015
Hi Geoff,
Thank you so much. It worked. Seems like the path becomes really weird when app is deployed.
Best,
Alexey

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 2 Jan 2015
Suggested that Alexey determine where the file feed.xlsx was stored/kept relative to the standalone application: in the same directory or elsewhere and asked that he include the full path (in the code) to the file just to see if that is what is causing the problem. Alexey verified the location of the file and checked that the app did work when the full path was indicated. The link http://stackoverflow.com/questions/17866534/get-the-location-of-a-deployed-matlab-application-at-runtime-for-mac-and-linux provided some code (for Windows) which would be able to determine the path to use to the file (assuming the file was in the same directory as the app).

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!