Does matlab web app have different paths?

3 vues (au cours des 30 derniers jours)
Denis
Denis le 31 Juil 2024
Im using Matlab App Designer.
The problem is that if the app was run locally everything works fine. If its uploaded to the Matlab Web App Server it appears to not find files which are in a different folder. In the app, there is a button which starts the main.m. The main.m shoul start other functions/programms.
The Folder structure is something like this:
  • app.mlapp
  • main.m
  • -Folder: m_files
  • A_calculate.m
  • B_review.m
  • C_plot.m
  • ...
I am defining paths like this:
addpath('.\_files'); % The folder name is used where the m files are stored
I am calling the functions like this:
A_calculate(arguments)
The Web app just seems to skip calling the function. No error, no logs in the web app log. If the mlapp is run locally it works perfectly fine.

Réponse acceptée

Avni Agrawal
Avni Agrawal le 31 Juil 2024
Hi @Denis,
I Understand that you are trying to deploy a MATLAB app to the MATLAB Web App Server, there are some differences in how paths and file access are handled compared to running the app locally. The issue you are encountering is likely due to the way paths are set or how files are accessed on the server.
Here are some steps and best practices to ensure your app works both locally and on the MATLAB Web App Server:
  • Use Absolute Paths: Instead of using relative paths, use absolute paths to ensure the server can find the files regardless of the current working directory.
  • Use `fullfile` for Cross-Platform Compatibility: Construct paths using `fullfile` to ensure compatibility across different operating systems.
  • Check the Current Directory: Ensure that the current working directory is set correctly on the server.
By following these steps, you should be able to ensure that your app works correctly both locally and on the MATLAB Web App Server.
function main()
% Get the path to the folder containing the app
appFolder = fileparts(mfilename('fullpath'));
% Set the current directory to the app folder
cd(appFolder);
% Define the path to the folder containing the m-files
mFilesFolder = fullfile(appFolder, 'm_files');
% Add the folder to the MATLAB path
addpath(mFilesFolder);
inputData = 5;
% Call the functions
resultA = A_calculate(inputData);
resultB = B_review(resultA);
C_plot(resultB);
end
Additional Tips:
  • Check Permissions: Ensure that the MATLAB Web App Server has the necessary permissions to access the folders and files.
  • Logging: Add logging to your app to capture any issues that might occur on the server. Use `fprintf` or the `log` function to write messages to a log file.
  • Debugging: If the app still doesn't work, add debug messages to check the current directory and the paths being used.
disp(['Current directory: ', pwd]);
disp(['m_files folder: ', mFilesFolder]);
By following these steps, you should be able to ensure that your app works correctly both locally and on the MATLAB Web App Server.
I hope this helps!

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Web App Server dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by