How can I determine if a matlab app is running as a web app?

I need to retrieve and save data differently when an app is running as a web app so I need something like is deployed that distinguishes between web deployment and standalone app deployment.

2 Comments

I found a suggestion that led me to solve the problem with this function which requires creating an empty file named, file.to.add.to.web.app, and adding that file to the compiled web app.
function tf = iswebdeployed()
% tf = iswebdeployed()
% tests whether an app is running as a web app
% must include a file named file.to.add.to.web.app when compiling a web app
% tf = isdeployed && exist('file.to.add.to.web.app', "file");
tf = isdeployed && exist('file.to.add.to.web.app', "file");
end
I would need something similar, my code would need something like "ismatlabonline" in addition to ispc, isunix and ismac... Nothing like this available?

Sign in to comment.

Answers (2)

The undocumented answer from here is this:
matlab.internal.environment.context.isWebAppServer
I have a few immediate uses:
  • deciding if a second figure can be opened
  • deciding if clipboard can be called
  • deciding about calling various system commands
It's frustrating that this is not a documented function, and a decent or comprehensive list of reasons for its use not documented. Or alternatively, that there were public capabilities that could be accessed like (matlab.environment.capability.ClipboardAvailable)
Web apps run in your browser and stand-alone app opens your system window(s) and run in it (them).

6 Comments

I know that, but I need to run different sections of code when it is running as a web app so I need something like isdeployed, say iswebdeployed.
This is just an idea:
How about using system command from MATLAB to see if there is something running (app) behind MATLAB? You may be able to find the process to raise a flag.
< system command>
worthless response...
I teach MatLab and some programs include readmatrix(); code is different because MatLab uses Linux instead of Windows server. I have comment out code to make the programs work.
MatLab sells MILLIONS of copies to mostly Window users but INSISTS on running LINUX force developers to percent out code...Stupid really stupid!
Mike McCullough, mike@mccul.co
I am not aware of any difference in readmatrix() between Windows and Linux ? Not unless the 'UseExcel' option has been specified?
This assumes that the file names have been properly constructed.
As a developer and seller of software, all files the user needs should NEVER be in the same folder. They need to be on a server or in the ROOT of C:. So my readmatrix(), open(), & load() have their files in a ROOT folder or:
weight = load('c:\appsM\54WEIGHT.DAT'); % C drive
weight = load('/MATLAB Drive/appsM/54WEIGHT.DAT'); % matlab drive
if ispc
filebase = 'C:';
else
filebase = '/MATLAB Drive';
end
filename = fullfile(filebase, 'appsM', '54WEIGHT.DAT');
weight = load(filename);
Hardcoding the base directory is a bad idea even on Windows, as doing so restricts you to a particular directory structure. You should be writing your code so that moving your files around requires only a small amount of changes to initialization.
Suppose that MATLAB Online were to switch to Windows. Then it isn't going to happen to have the same directory structure that you have.

Sign in to comment.

Categories

Products

Tags

Asked:

on 2 Nov 2020

Edited:

on 23 Sep 2025

Community Treasure Hunt

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

Start Hunting!