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:
- Open your App Designer app in MATLAB.
- Click on the "Apps" tab in the MATLAB toolstrip and select "Add-Ons > Manage Add-Ons".
- In the "Manage Add-Ons" dialog box, click on the "Installed" tab and locate the "MATLAB Compiler" product.
- Click the "Settings" button next to the "MATLAB Compiler" product to open the "Compiler Settings" dialog box.
- In the "Compiler Settings" dialog box, go to the "Files and Folders" section and select the "Required Files" tab.
- Click the "+" button to add your Excel file to the list of required files.
- In the "Include file" dialog box, navigate to the location of your Excel file and select it.
- 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 :
appDir = fileparts(mfilename('fullpath'));
excelFile = fullfile(appDir, 'XXX.xlsx');
[num,txt,raw] = xlsread(excelFile, 'SHEET1');
[num1,txt1,raw1] = xlsread(excelFile, 'SHEET1');