How to compile a Matlab code developed using App Designer with batch run available

8 visualizaciones (últimos 30 días)
Hello,
I have a Matlab code developed using App Designer and I want to compile it with following details:
The application has GUI and user should be able to select option A and B. (option A and B have different solving algirhtm behind).
Once user select either option A or B, it will show multiple parameters that user should give. (param 1, param 2, param 3,...: these parameters will be directly used for solving)
After user give parameters manually and click "solve" button, it will return results on the GUI.
I want to make the all user's activities(select run type option A and B, give parameters and click run button) to batch script something like
matlab.exe "filename", "option A", "param 1, param 2, param 3,...." so that user can run the code in batch mode not in GUI mode.
Thank you!
  1 comentario
Rik
Rik el 7 de Ag. de 2023
I doubt this can be done with AppDesigner, but you can certainly compile a function that runs with a GUI if you don't provide inputs and runs without a GUI if you don't.
Alternatively, you can add a field to your GUI where the user can paste the syntax. That will not allow paralel execution, but it will provide an easy way to implement a batch mode.

Iniciar sesión para comentar.

Respuestas (1)

Yatharth
Yatharth el 23 de Ag. de 2023
Hello,
I understand that you want to compile the MATLAB code developed using App Designer with batch run.
To compile your MATLAB code developed using App Designer into a batch script, you can follow these steps:
1. Export the App Designer code to a standalone MATLAB file:
  • Open your App Designer project in MATLAB.
  • Extract the necessary code that performs the solving algorithm and result display.
  • Copy the code in a MATLAB file.
  • Modify the code to accept command-line arguments for option selection and parameters.
  • Save the modified MATLAB file.
2. Create a batch script:
  • Open a text editor and create a new file.
  • Add the following lines to the batch script:
@echo off
matlab /r "option='%1';num1=%2;num2=%3;sum_script;"
  • Save the file with a .bat extension
3. Call the bat file from terminal:
  • Call the bat file following with input arguments :
  • filename.bat A 2 3
here’s an example for you:
1. Creating sum_script.m
% Check if the input arguments are valid numbers
% Note : that num1 , num2 and options are not defined in the code
if isnan(num1) || isnan(num2)
error('Invalid input. Please provide valid numbers.');
end
if option == 'A'
sumResult = num1 + num2;
disp(['The sum of ' num2str(num1) ' and ' num2str(num2) ' is: ' num2str(sumResult)]);
else
sumResult = num1 - num2;
disp(['The difference of ' num2str(num1) ' and ' num2str(num2) ' is: ' num2str(sumResult)]);
end
2 . Creating the run_sum_script.bat
@echo off
matlab /r "option='%1';num1=%2;num2=%3;sum_script;"
3. Running the .bat file from command line
run_sum_script.bat A 7 8
you can refer to the following link for various syntax while passing input parameters when running MATLAB in batch mode

Categorías

Más información sobre Standalone Applications en Help Center y File Exchange.

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