Issue with MATLAB not finding my excel file even though its in the same folder as the .exe

11 visualizaciones (últimos 30 días)
I have a script that takes in data from an excel file. It works fine it seems in the IDE, but when I complie the code as an app for deployment
MATLAB no longer can find the excel file event though its in the same folder as my .exe
% read in excel data
[num,txt,raw] = xlsread('XXX.xlsx','SHEET1');
[num1,txt1,raw1]=xlsread('XXX.xlsx', 'SHEET1');
Can anyone help me out?
Thank you in advance,
Billy

Respuesta aceptada

Satwik
Satwik el 22 de Jun. de 2023
When you deploy your MATLAB code as an executable app, you need to make sure that all required files, such as the Excel file in your case, are included in the app package and accessible by the deployed app.
To include your Excel file in the app package, you can add it to the "Required Files" section in the App Designer by following these steps:
  1. Open your App Designer app in MATLAB.
  2. Click on the "Apps" tab in the MATLAB toolstrip and select "Add-Ons > Manage Add-Ons".
  3. In the "Manage Add-Ons" dialog box, click on the "Installed" tab and locate the "MATLAB Compiler" product.
  4. Click the "Settings" button next to the "MATLAB Compiler" product to open the "Compiler Settings" dialog box.
  5. In the "Compiler Settings" dialog box, go to the "Files and Folders" section and select the "Required Files" tab.
  6. Click the "+" button to add your Excel file to the list of required files.
  7. In the "Include file" dialog box, navigate to the location of your Excel file and select it.
  8. Click "Open" to add the file to the list of required files.
Now, when you deploy your app using the MATLAB Compiler, the Excel file will be included in the app package and accessible by the deployed app.
In your code, you can access the Excel file using the mfilename function to get the full path to the directory where the executable app is located, and then use the fullfile function to build the full path to the Excel file, like for example :
% get the full path to the directory where the executable is located
appDir = fileparts(mfilename('fullpath'));
% build the full path to the Excel file
excelFile = fullfile(appDir, 'XXX.xlsx');
% read in excel data
[num,txt,raw] = xlsread(excelFile, 'SHEET1');
[num1,txt1,raw1] = xlsread(excelFile, 'SHEET1');

Más respuestas (1)

Image Analyst
Image Analyst el 22 de Jun. de 2023

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by