How to generate embedded c/c code in MATLAB for GUI code's ?

8 ビュー (過去 30 日間)
RJS
RJS 2021 年 12 月 15 日
編集済み: Purvaja 2025 年 6 月 10 日
I made a GUI in MATLAb and I want to dump this gui in Microcontroller for which i want to generate Embedded c/c code for gui,I found some video to convert m file , but I dont know how to do for GUI? please help
  1 件のコメント
Infinite_king
Infinite_king 2024 年 4 月 15 日
編集済み: Infinite_king 2024 年 4 月 15 日
Code generation is not supportef for GUI functions. How did you develop the GUI application, throught App designer ?

サインインしてコメントする。

回答 (1 件)

Purvaja
Purvaja 2025 年 6 月 9 日
編集済み: Purvaja 2025 年 6 月 10 日
Hi @RJS,
There’s a key limitation for deploying code to microcontroller using Embedded Coder: GUIs built with App Designer or GUIDE cannot be directly converted to C code or deployed to embedded hardware. These GUIs rely on MATLAB’s desktop runtime, which microcontrollers can’t support.
However, you can still deploy the computational logic (e.g., multiplying two numbers) by transitioning your GUI-based application to a Simulink model.
Workaround steps:
  1. Extract the core logic from your GUI (e.g., a × b → result).
  2. Recreate the logic in Simulink using blocks like Inport, Product, and Outport.
  3. Replace GUI elements with hardware-compatible interfaces:
  4. EditField Analog/Digital In (or Inport)
  5. ButtonGPIO Pin Input
  6. DisplaySerial Output, LED, or LCD
  7. Use Embedded Coder + Hardware Support Package to generate and deploy code.
Example: Multiplying 2 numbers
  • In App Designer
% Callback for Multiply Button
function MultiplyButtonPushed(app, event)
a = app.InputA.Value;
b = app.InputB.Value;
result = a * b;
app.OutputLabel.Text = num2str(result);
end
This is fine for simulation, but not deployable.
  • Extracting the Logic
function y = myLogic(a, b)
%#codegen
y = a * b;
end
Once extracted, you can:
  1. Import this logic into a MATLAB Function block in Simulink.
  2. Configure the Simulink model for your target hardware.
  3. Generate C/C++ code and deploy it using Embedded Coder.
For more clarifications refer to following documentation links:
  1. Functions not supported for code generation : https://www.mathworks.com/help/coder/ug/function-is-not-supported-for-code-generation.html
  2. Supported hardware in embedded coder: https://www.mathworks.com/help/ecoder/supported-hardware.html
Hope this gives you a clear direction. Once your logic is working in Simulink, hardware deployment is straightforward.

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by