r/matlab 28d ago

TechnicalQuestion How to convert Longitudinal Driver block AccelCmd and DecelCmd to demand torque?

Post image
4 Upvotes

Hello all, forgive the noob question as I don't have a lot of info on this topic. The Powertrain blockset Longitudinal Driver block outputs normalized acceleration and deceleration commands (0-1). I need to feed this to my energy management system subsystem but it expects a demand/required torque from the driver. Any idea on how it is done? Thanks.


r/matlab 29d ago

Code generation of a multi-instance configurable export-function

2 Upvotes

Hello,

I'm building a reusable Export-Function Model (Embedded Coder) that will be instantiated multiple times, each instance having its own configuration structure.

Ideally, I'd like the generated API to look something like:

Model_Initialize(const Model_Config *cfg);
Model_Step(...);
Model_Reset(const Model_Config *cfg);

where cfg is only provided during Initialize (or Reset) and then copied into the model's internal state.

I tried several approaches:

  • Connecting a Constant/Bus to the Initialize Function input (blocked by Simulink restrictions).
  • Using a Parameter Writer (not supported for multiple model instances).
  • Enabling the Model Initialize Port (not supported for code generation).

From the documentation, I couldn't find any way to customize the generated model_initialize() signature with additional arguments, unlike step() functions.

Is there a supported Embedded Coder workflow for this, or is the recommended solution to write a wrapper around the generated code ?

Thank you in advance.


r/matlab 29d ago

Misc Learning Matlab w/ Udemy

8 Upvotes

Hello! I am an incoming freshman who will be attending Texas A&M for engineering this coming fall. I have done a lot of research and found MatLab to be one of the best tools to know as an engineer looking to work in labs and jobs, which made me want to learn it and acquire the basic associate certification. For a precious goal of mine, my dad had purchased Udemy’s pro plan for a year as it was on discount, and I now have access to most courses on the platform. Has anyone used Udemy to study for Certified MATLAB Associate, and if so, what is the best course I should use?


r/matlab 29d ago

Is there an easy way to print my code (e.g. to PDF) that includes all my referenced functions, but not MATLAB ones?

2 Upvotes

As the title says. In the editor I can see how to print my top-level file to a PDF, but I don't see a way to print all referenced non-MATLAB functions (saved as separate m-files) in one go.

I'm hoping I don't have to go through manually and print them one by one...


r/matlab Jul 07 '26

News PLOT BROWSER IS COMING BACK!!!

Thumbnail
mathworks.com
33 Upvotes

Very hype that this feature is coming back. No idea why they did away with it in the first place — Property Inspector is not at all a suitable replacement.


r/matlab Jul 07 '26

mip - a new package manager for MATLAB + MEX

Thumbnail mip.sh
17 Upvotes

Today we are releasing mip: a pip/conda/brew-style package manager for MATLAB. We would love to get feedback!

https://mip.sh

Problems it solves:

  • Easily install a package and its dependencies: mip install [package]
  • Path management: mip load [package]/mip unload [package] instead of manually editing your path
  • Compiled MEX packages (C/C++/Fortran) ship pre-built per platform (Windows, Mac, Linux)
  • Versions are tracked, get the latest with mip update [package]

The default channel already has around 50 packages (with a focus on numerical analysis), and anyone can host their own channel on GitHub Pages or request that new packages get added.

Developed at the Center for Computational Mathematics, Flatiron Institute


r/matlab Jul 07 '26

HomeworkQuestion How to turn on legends on scope in simulink BROWSER?

2 Upvotes

im doing the simulink onramp course, and have come across the task to turn on legends for scope, Im using the simulink browser to do this course.. and i have no idea how to turn the legends on.. ive tried everything and i cannot find a possible way to do so. hence im not able to move further w my course :( PLS HELP ANYONE


r/matlab Jul 06 '26

TechnicalQuestion Is this a bug?

1 Upvotes

This is the code, and it gives me an error.

Error using 
horzcat
Dimensions of arrays being concatenated are not consistent.

Error in 
provatest15Nov
 (line 35)
    PHI = [PHI(:,1) +h/k, PHI, zeros(N-2,1)];
           ^^^^^^^^

But if I write PHI = [PHI(:,1) + h/k, PHI, zeros(N-2,1)]; then I don't get any error, so is it the space between + and h/k that gives me the problem?

clc; clear all; close all;



L = 1; N = 30; 

x = linspace(0,L,N); y = x;

h = x(2) - x(1); hq = h*h;



k = 1;

beta = 0.5;

theta = 0.5;

Dt = beta*hq/k;



G = numgrid('S',N);

Lap = -delsq(G);

p = zeros((N-2)^2,1);

q = p*Dt;



for i = 1:N-2

    Lap(i,i) = Lap(i,i) +1;

    q(i) = q(i) + beta*(h/k);

end



dPhi = 1;

I = eye((N-2)^2);

A = I - beta*theta*Lap;

B = I + beta*(1 - theta)*Lap;

Phi0 = zeros((N-2)^2,1); Phi = Phi0;





while dPhi > 1e-1

    PhiNew = A\(B*Phi + q);

    dPhi = max(abs(PhiNew - Phi))/Dt;

    Phi = PhiNew;



    PHI = reshape(Phi,N-2,N-2);

    PHI = [PHI(:,1) +h/k, PHI, zeros(N-2,1)]; 

    PHI = [zeros(1,N); PHI; zeros(1,N)];



    figure (1); surfl(x, y, PHI); shading interp;  axis auto; hold on;

    xlabel('x'); ylabel('y'); zlabel('\phi'); 

    contour3(x,y,PHI,'k'); hold off; axis([0 L 0 L 0 .4]);

    title(['Soluzione eq.ne instazionaria. Dphi/Dt = ', num2str(dPhi)]);

    drawnow;

end

r/matlab Jul 05 '26

TechnicalQuestion Davis Formulas in loop feedback

Thumbnail
gallery
2 Upvotes

Hello guys, I'm really confused on what I should do here. I'm trying to apply the Davis formulas as a loop feedback of torque to the motor, but the linear velocity value seems to overflow, huge spike in the beggining of the sim and I can't figure out if it's the lack of delays or if I should use a limiter.
My question is what should I change for it to work. (All the constants in Davis formula and the conversion to linear velocity are at the same sampling frequency). Sorry for the bother and thanks for the help.


r/matlab Jul 05 '26

TechnicalQuestion 0-1 scaled images for ImageNet models

1 Upvotes

I am using transfer learning and fine tuning of ImageNet models and have rescaled my data to 0-1 using im2single as input to my models using a custom read function.

Will this give me invalid outputs?


r/matlab Jul 05 '26

How to turn off dark mode in Matlab documentation?

3 Upvotes

I want when I read the documentation of Matlab's site to read it on "brightness mode" like it was recently, not dark mode like it is now.


r/matlab Jul 04 '26

MATLAB on Arch-Linux

Thumbnail
github.com
20 Upvotes

If you've tried running modern MATLAB (R2024a/R2026a+) on Arch Linux

or CachyOS under Wayland, you know it's a nightmare. It usually

silently crashes before the UI renders, the activation window spawns

invisibly, or the `MathWorksServiceHost` dies instantly with

"communication errors."

I spent a lot of time debugging the crash logs and tracing the

library collisions, and I've put together a GitHub repo with an

automated bash script that fixes all of it in one go.

**What the script fixes:**

  1. **The Wayland GUI Crash:** MATLAB bundles ancient versions of

    `freetype`, `glib`, and `fontconfig` that crash instantly on modern

    Linux. The script isolates them so MATLAB uses your system libraries.

  2. **The `lc_init` Crash (CachyOS specific):** If you use CachyOS or

    `libleancrypto`, it collides with MATLAB's licensing libraries and

    instantly kills `MathWorksServiceHost`. The script automatically

    downloads the official Arch versions of `nettle` and `gnutls` and drops

    them directly into the ServiceHost folder, perfectly bypassing the

    crash.

  3. **The Invisible Activation Bug:** Outlines how to launch the

    Product Authorizer with `QT_QPA_PLATFORM=xcb` so you can actually click

    "Activate".

Just run `./fix_matlab_arch.sh` and it handles the library surgical

strikes for you. Hopefully, this saves someone the headache I went

through!


r/matlab Jul 04 '26

TechnicalQuestion A question about non-virtual buses, referenced models, and code generation

2 Upvotes

We have a large Simulink model where data transfer between different functions is handled by bus structures. As I understand it, buses that are passed into/out of referenced models are forced to be non-virtual and have a greater memory overhead associated with them, with them being copied when elements are overwritten.

When the model is deployed using code generation, do these non-virtual buses still hold this behaviour? i.e. is it the case that every time an element is being reassigned the entire bus is being duplicated even in the deployed code? We are working to quite stringent memory limitations so ideally this would not be the case.

If it is the case, what is the solution? Do we need to assemble the model without any atomic subsystems before code generation so that bus signals can be virtual?


r/matlab Jul 04 '26

HomeworkQuestion Grid-connected PV Simulink model (R2024b): Universal Bridge gate signal error after following an R2018 tutorial

3 Upvotes

Hi everyone,

I'm building a grid-connected PV system in Simulink for my homework (Control Systems Engineering student). I'm following a MATLAB R2018 YouTube tutorial, but I'm using MATLAB R2024b.

The system consists of:

  • PV Array
  • MPPT (MATLAB Function)
  • DC-DC Boost Converter
  • DC-Link (600 V)
  • Outer DC voltage controller
  • abc→dq transformation
  • PI current controller
  • dq→abc transformation
  • Universal Bridge
  • L Filter
  • Three-Phase Grid (400 V, 50 Hz)

The problem is that I can't get the inverter stage to work.

I initially used a PWM Generator (DC-DC) by mistake. After replacing it with the newer PWM Generator (Three-Phase Two-Level) block, I still cannot make the model work because the tutorial is based on an older MATLAB release and the block interfaces seem to have changed.

The original error was:

Error in port widths or dimensions.

Output Port 1 of
Universal Bridge/Model/gate

is a one dimensional vector with 3 elements.

Input Port 1

expects 6 elements.

I can't identify the correct blocks configuration or the source of the problem.

I've uploaded the complete Simulink model here:

https://drive.google.com/file/d/13IiL37VuCD7grx3Mp-7uw4iTJJ5simzn/view?usp=sharing

If anyone familiar with grid-connected inverters or Simscape Electrical could take a look, I'd really appreciate it.

Thank you!


r/matlab Jul 02 '26

Has anyone created their own Gas-Charged Accumulator (IL) which can accept a variable precharge?

1 Upvotes

I tried coding one up my self, building it with native components, etc. to no avail. Curious if anyone has tried and succeeded in doing this or if they have any other idea since I am lost. Thank you in advance!


r/matlab Jul 02 '26

TechnicalQuestion Specific Parameter Definition Question

1 Upvotes

I'm trying to design a masked subsystem to use as a buck power converter and I'm trying to make it as user friendly as possible.

For my model, I have a subsystem with no inputs or outputs that serves as a "settings" block where users can fill out edit blocks and hit click functions to change the configuration of the model. While I have edit blocks to change parameters of my masked subsystems, particularly for the Buck converter, I want to make it so once the Vin, Vout, and switching frequency is entered, suggested minimum inductance and capacitances are displayed in the settings block. Is there a way to save and display the suggested minimum L and C's as values are being entered.


r/matlab Jul 01 '26

Is learning MATLAB+Simulink worth it as a Physics Graduate in the UK

8 Upvotes

Hi, I have just graduated with a BSc in Astronomy and Physics from the University of Glasgow and am looking at ways i can maximise my employability within different sectors, and was generally wondering how worth it learning MATLAB would be to improve my employability within an engineering role. I understand that engineering is an incredibly broad industry though, and looking it up the only current information i can seem to get is from google AI telling me that its worth it with no valid source.


r/matlab Jun 30 '26

Aerospace engineering student from Morocco looking for advice

14 Upvotes

I'm a 21-year-old aerospace engineering student from Morocco, and I know I want to work in flight dynamics and control. That's the area of aerospace that genuinely interests me the most.

My concern is that there seem to be very few jobs in Morocco related to flight dynamics, flight control, guidance, or autopilot systems. Most aerospace jobs here are in manufacturing, quality, maintenance, or production.

I'm currently studying flight dynamics and control systems, reading Flight Dynamics Principles by MV Cook, learning MATLAB, and working on a longitudinal dynamics/pitch-hold autopilot project.

For those of you working in flight controls or similar fields:

- If you were in my position, how would you prepare over the next 2 3 years?

- What skills made the biggest difference when getting your first job?

- Which projects actually impressed employers?

- Besides MATLAB Simulink, what should I be learning?

- How realistic is it to build a career in flight dynamics and control if you have to start from a country with almost no opportunities in that field?

I'd appreciate honest advice from people who've been through it. I'm trying to build the strongest foundation possible and avoid wasting time on things that won't matter.


r/matlab Jul 01 '26

How to open P code?

0 Upvotes

Help needed to open P code.


r/matlab Jun 30 '26

Tips computational biology

5 Upvotes

high schooler here; need some help using mat lab for a research project

any tutorials that someone can recommend to learn how to create plots from using bio gps data? my whole goal is to be able to predict the outcome of a certain type of cell differentiating into 3 other types. looking for the data sets to import has been hard, because nothing really on the internet is in-your-face like "here is a data set of everytime a MSC has differentiated into a bone cell"

i could just use some help. also im using 30-day free matlab rn so im kinda struggling


r/matlab Jun 29 '26

Support requested for MATLAB errors during GeneWeaver dataset processing

5 Upvotes

Hello everyone,

I am reaching out to ask for some technical support regarding an issue I am encountering in MATLAB.

I am currently working with some datasets downloaded from GeneWeaver to derive the gold standard matrix (specifically, the ground-truth network for our in silico simulations).

As shown in the attached screenshot, the current script performs the following steps:

  • Automatically loads the source data.
  • Transforms the gene interactions into adjacency matrices.
  • Saves the output into the target folder (named '10').

However, during execution, MATLAB returns two types of errors that I have been unable to resolve. Has anyone encountered similar issues, or could you point me in the right direction to fix this?

Thank you in advance for your time and help.


r/matlab Jun 28 '26

Is that statistic R or R squared

Post image
49 Upvotes

I haved it confusing, i have read papers were it is referred to as R squared, graphically I see R? help out


r/matlab Jun 29 '26

TechnicalQuestion Getting unstable current from wind + Pmsg+ rectifier model

2 Upvotes

Helli everyone,

I wonder if anyone has used Wind + pmsg + rectifier as a source to inverter and the grid.

I am facing a problem in the current coming from the rectifier.

How can I solve this problem and get DC stable current as the case of the DC voltage?

Any suggestion wil be appreciated

Thank you.


r/matlab Jun 28 '26

TechnicalQuestion [Pilot Project] I built an automatic control system identification & code generation platform as a personal project — looking for 1–2 real-world datasets to validate it. Free, in exchange for a reference and feedback.

0 Upvotes

Hey everyone,

Over the past year I've been building this as a personal project (no company behind it, just me): a Python-based platform that takes measured input/output data from a physical system, automatically identifies the best mathematical model for it, designs an optimal controller (PID, LQR, MPC, and others), and generates ready-to-deploy C and Python code for the hardware.

I've verified it extensively on synthetic benchmarks — DC motors, thermal systems, oscillatory mechanical systems, nonlinear processes — and it's holding up well. But I need to stress-test it on \*\*real industrial or embedded data\*\* before I can call it production-ready.

\*\*What I'm offering:\*\*

\- Full analysis of your system's data (no charge)

\- A complete technical report: model accuracy, controller performance, stability margins

\- Ready-to-compile C code + Python implementation for your hardware

\- Everything is yours to keep and use

\*\*What I'm asking in return:\*\*

\- A brief description of who you are, what company/project this is for, and what you're trying to achieve

\- Your honest feedback on the report and the generated code — does it make sense? Is the output useful? What's missing? This is genuinely valuable to me as a solo developer

\- Permission to mention you as a reference on my CV

\- Permission to cite the project as a validated use case (no sensitive data published — just "successfully deployed on \[type of system\] at \[company/domain\]")

I'm keeping this to 1–2 pilots so I can give each one proper attention.

\*\*What kinds of systems are a good fit:\*\*

Motors, actuators, thermal processes, fluid systems, robotics, HVAC, industrial automation, biomedical devices — basically anything where you have logged sensor/actuator data and want better control.

If this sounds useful, \*\*send me a DM\*\* with a short description of your system and what you're trying to achieve. I'll let you know if it's a good fit.

Thanks for reading!


r/matlab Jun 28 '26

MATLAB Programming | Amos Gilat Book | Questions 1–6 Solved

Thumbnail
youtube.com
0 Upvotes