This question already has an answer here:
Open a GUI directly from desktop (Shortcut) in MATLAB environment
(1 answer)
Closed 5 years ago.
I have written a MATLAB function which can send an e-mail. I can call this function from the command prompt, using the following command:
"C:\Program Files\MATLAB\R2017a\bin\matlab.exe" -r "nameofthefunction;"
When I do this, the MATLAB application opens, and then the function is executed. What I want to do is write a command which would trigger the function (i.e send the e-mail), without opening the MATLAB application.
To run a MATLAB function you need to use either (1) the MATLAB environment or you need to (2) convert it to a standalone component. The first is obviously using the MATLAB GUI, as you call it, but maybe it is an option to close it down after using the function
"C:\Program Files\MATLAB\R2017a\bin\matlab.exe" -r "nameofthefunction; quit;"
For (2) look at the MATLAB Compiler and check whether your function can be converted into a standalone component.
Related
I am trying to use some existing matlab scripts within the openmdao. The external code tutorial is straight forward to follow. However, I encounter some issues when modifying the following example for matlab applications.
original code in tutorial:
self.options['command'] = ['python', 'extcode_paraboloid.py', self.input_file, self.output_file]
modified code for matlab applications:
self.options['command'] = ['matlab', '-nodesktop -r "run Paraboloid.m"', self.input_file, self.output_file]
This line is okay to launch matlab. However, other arguments('-r "test.m "') seems have been truncated and can not be interpreted by matlab correctly. The alternative solution I have is to create another .py file for calling os command.
os.system('cmd /c "matlab -nodesktop -r "run Paraboloid.m",quit"')
Any suggestion on how to call the matlab function directly? Thanks!
Try breaking everything up wherever there is a space.
self.options['command'] = ['matlab', '-nodesktop', '-r', '"run Paraboloid.m"', self.input_file, self.output_file]
This question already has an answer here:
Can I change the prompt in MATLAB?
(1 answer)
Closed 5 years ago.
This question has been marked as a duplicate of another question asking about the possibility of
displaying the current system hostname in the prompt. The accepted answer to that question successfully uses the same custom prompt,
called setPrompt(), as does the accepted answer to this question (see below).
Please note however: that question does not talk about
date/timestamps, nor does the answer give detailed step-for-step
instructions. The answer below does both of those things and might, or
might not, therefore be the best-suited answer for you.
It can be useful to know when (e.g. "11:32 pm") a Matlab command has been executed. I have been looking for the possibility to show a date/timestamp in the Matlab prompt. I am using Matlab R2017b on Windows 10.
Is that possible, and if so, what are the step-for-step instructions for implementing such a prompt?
Preferably I want it to look like the following:
[13:45:57] >> 1
ans =
1
[13:45:58] >>
Note: It turns out that it is indeed possible, check the answer (self-written).
As of the R2017b release, it is possible to display command execution timestamps using
setPrompt,
a custom command prompt from the Matlab File Exchange (see instructions below).
For a technical explanation of the code, see the
author's
original blog
post
about setPrompt.
Configuring a custom prompt
Configuring a custom prompt is easy and takes only a few minutes.
Download and extract setPrompt.m into your Matlab path (find it with the userpath command).
If you want to set the prompt permanently, you can put a call to setPrompt() in your startup.m file.
If you haven't configured your startup file, simply go to the Matlab command line and do:
userpath
cd <YOUR_USERPATH>, (usually C:\Users\<USER>\Documents\MATLAB).
edit startup.m, click "yes", and add your setPrompt call into the file.
As an example, you can put setPrompt('<timestamp> ') in your startup file to get a continuously updated date/timestamp prompt. To get back the default prompt, call setPrompt without arguments.
>> setPrompt('<timestamp> ')
<06-Feb-2018 01:00:51>
<06-Feb-2018 01:00:53> setPrompt()
>>
To get exactly what I wanted I used setPrompt('[''['',datestr(now, ''HH:MM:SS''), ''] >> '']')
>>
>> setPrompt('[''['',datestr(now, ''HH:MM:SS''), ''] >> '']')
[13:45:57] >>
[13:45:57] >> 1
ans =
1
[13:45:58] >>
I am trying to run a Matlab script from a tcl file.
There are examples elsewhere of how to do this (eg Running Matlab Command From Tcl) :
exec {*}matlab -nodisplay -nosplash -nodesktop -r "ScriptTitle; quit"
However, as far as I can see, this works by opening up a new Matlab command window before executing the Matlab script.
However, I want to call the Matlab script as part of a loop, meaning it will be called many times by my tcl code. Each time matlab is called, a new matlab command window is opened. This takes a long time as the new command window has to open and load etc before it does anything. I want to know if there is a way to access an already open matlab command window from tcl? Or, alternatively, is there a more efficient way to run Matlab from tcl that would work well as part of a frequently repeated loop?
MATLAB has an API engine which can be used to control it remotely. To use it from Tcl, you can write an extension or use Ffidl.
I have timeseries files with their own extension (.Z4R). I have compile my matlab GUI that read them.
Right now I load these files from the GUI (look for the path...). I wondering if it's possible to just double-click on the .Z4R in order to load it into my program.
Thank you.
I understand the window part.
Where I don't know it is about this command line that accept the input (Z4D) when the GUI .exe starts. How do I know the path of the double-clicked file.
Thanks
Marc
You should be able to do this via Windows file association (assuming you are running windows).
You'll need to check the command line arguments of your app and open supplied Z4R files as appropriate.
Have a look on google to see how to set-up file associations
If your compiled Matlab GUI was created using the Matlab tool guide, you should have a function
function YourProgramName_OpeningFcn(hObject, eventdata, handles, varargin)
varargin should contain the filename you double clicked on.
I'm using Matlab and need to get an ASAP2 (a2l) file exported from a Simulink model, using the Real-Time Workshop toolkit, from the command-line so it can be run as part of a batch operation.
I know that the process is possible by following the standard procedure for generating an ASAP2 file from a model, via the GUI, but this is no use to me in this instance as it requires user interaction with the GUI.
I've scoured Google and the Mathworks forums for an answer to this one but have come back with nothing; so does anyone know the command to generate an a2l file from the Windows CLI?
Thanks for any help you can offer.
Is the a2l file being generated when you press Build or Generate Code on the GUI? If so, the command-line equivalent is
rtwbuild(model);
Re-reading your question, I think you might be asking how to generate the file from a Windows command prompt. You can startup MATLAB and have it run any command using the -r option,
% matlab -r "load_system('model'); rtwbuild('model'); quit;"
Or you can write a a script to do all this, and call that script.