r/matlab

▲ 2 r/matlab+1 crossposts

How can I validate a P&ID for an R717 pumped-overfeed evaporator valve station for a graduation thesis?

Hi everyone on reddit!,

First of all I am fairly new to industrial refrigeration systems, I am doing a engineering study.

I am working on a graduation thesis in industrial refrigeration. The project is about a standardized evaporator valve station for an ammonia system. The system is based on R717 pumped-overfeed evaporators with hot-gas defrost.

The valve station is divided into four functional sections:

  • Liquid Feed
  • Wet Return
  • Hot Gas Defrost
  • Defrost Drain

The goal is not to certify a real installation, but to prove in my thesis that the proposed P&ID is functionally plausible and can operate in different modes, such as:

  • normal cooling
  • part-load operation
  • pump-down / isolation before defrost
  • hot-gas defrost
  • defrost drain / pressure equalisation
  • return to cooling

I am struggling with how to prove this properly to my tutor. I can make calculations for mass flow, pressure drop and Kv values, and I can compare component sizing with Danfoss Coolselector². I can also make an operating-mode matrix that shows which valves are open or closed in each mode.

However, I do not have a real installation available for live testing, and even then there are no inline flow meters in the system.

My question is:

What would be a technically acceptable way to validate this kind of P&ID for a graduation thesis?

I am especially interested in how engineers normally prove that a valve arrangement is functionally correct before it is built or commissioned.

Any help would be greatly appriciated!

reddit.com
u/Bobk97 — 1 day ago
▲ 1 r/matlab

Function Practicality

I am coding in MATLAB for a couple of my aerospace classes, particularly for Aerodynamics and Gas Dynamics. I have made functions for quite a few processes that I plan to be using in other projects and class assignments. I was wondering if it was a bad idea to have any interactable elements in the function. Basically, if a user wanted to state which variable they want to solve for in the isentropic relations, I would use a menu. I do have a different method that would work without any interaction, but I like the idea of the interactive part. Also, is it a bad idea to use the solve function for these complex equations? I had been using ChatGPT to debug and it first suggested solve many functions ago, and after trying to use my functions with arrays and plotting, it told me it was a terrible idea. I was hoping for some human feedback. Thank you for your time!

reddit.com
u/BxSFire — 1 day ago
▲ 24 r/matlab

Can you design an automated driving scenario with AI?

You need to generate a lot of scenarios to test automated driving algorithms and a colleague of mine decided to use AI to assist scenario generation. Check out what he could do with MATLAB Agentic Toolkit and RoadRunner.

u/Creative_Sushi — 3 days ago
▲ 0 r/matlab

get around matlab's cd()

When profiling a script I noticed that cd() calls in a loop take a lot of time. Different parts of the loop operated on files in different folders, hence cd()'s inside that loop.

I fixed it by adding full paths to file names instead of cd'ing.

I read though that matlab's cd is slow because it does not just change pwd, it also scans that directory for any matlab files. Is there a way around it, i.e. to change the default directory for save/load/fopen etc but suppress that scanning? Sometimes cd might more convenient than full paths

reddit.com
u/IAmMDM — 5 days ago
▲ 3 r/matlab

Fixed Step Solver timing issues in Simulink

I'm pretty new to simulink and I'm trying to get the climate control example running with fixed step timing, so it can be exported and run in another system.

It runs fine out of the box of course. So I change it to fixed step timing and change the function generator's period and pulse width parameters to be a multiple of the fundamental sample time, and it'll build. But when it runs I get the error below. I've tried reducing the step size and changing the solver but getting the same result. Hoping somewhere here could point me in the right direction.

It seems like the Tcabin block is trying to divide by zero but I'm not familiar enough with simulink to work through debugging it.

Error:An error occurred during simulation and the simulation was stopped

Caused by:

Derivative of state '1' in block 'sldemo_auto_climatecontrol_tcdebug/Interior Dynamics/Tcabin' at time 0.1 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)

reddit.com
u/tennispro9 — 4 days ago
▲ 3 r/matlab

2nd order differential equation

Hi, I’m currently struggling on how to input my 2nd order differential equations int o matlab and how to solve it I’ve tried YouTube tutorials but it seems to not make any sense/ difference
Would appreciate any advice on how to solve this issue
I’ve currently not attached the equations in post .

reddit.com
u/MarionberryOk95 — 6 days ago
▲ 44 r/matlab+3 crossposts

DTC with Third Harmonic Injection as a modulator

I’m currently working on a simulation project based on DTC with Third Harmonic Injection PWM (DTC-THIPWM) for an induction motor drive.

Instead of using the classical DTC approach with hysteresis comparators and switching tables, I adopted a DTC-SVM-style architecture, but replaced the Space Vector Modulation stage with Third Harmonic Injection PWM (THIPWM).
The goal was to keep the fast dynamic response and decoupled torque/flux control advantages of DTC while using a PWM generation method that is simpler and computationally lighter than SVM.

The system behavior is actually good overall:

  • Speed tracks the reference correctly
  • Flux converges nicely to the reference
  • Mean electromagnetic torque converges properly as well

However, the issue is with the instantaneous electromagnetic torque.
Even though the average torque is correct, the raw torque waveform contains a large ripple that I cannot fully explain.

Simulation setup

  • Speed reference: step input at t = 0 s
  • Reference speed: 150 rad/s
  • Load torque: 5 N·m
  • Sampling time: Ts = 1e-6
  • Control period: Tol_Ts = 10*Ts
  • PWM frequency: 2 kHz

What confuses me is that:

  • The PI controllers seem validated since the mean values converge correctly
  • Rotor speed is relatively stable
  • Flux estimation looks fine
  • But the electromagnetic torque ripple remains significant in steady state

At this point I suspect the ripple could be caused by:

  • THIPWM harmonic content
  • Low PWM frequency
  • Torque estimation noise
  • Flux estimation inaccuracies
  • PI interaction
  • Or maybe replacing SVM with THIPWM fundamentally changes the voltage vector quality

Has anyone worked on something similar or seen this kind of behavior in DTC-THIPWM structures?
I’d really appreciate any insight on where this ripple could realistically come from.

u/Basic-Courage-8759 — 6 days ago
▲ 45 r/matlab

[Beta] Decoupled Plotting Library for MATLAB

A couple of months ago, I shared a video of an asynchronous plotting library that renders outside the main MATLAB thread. We are finally in public beta with accessible documentation and open-source examples.

Here is a video of what the current examples look like: https://www.youtube.com/watch?v=N0KiHP6UPKY

The code is at https://github.com/HebiRobotics/hebi-charts-examples in case anyone wants to try it out.

u/OddEstimate1627 — 6 days ago
▲ 5 r/matlab+2 crossposts

Machine Learning Thesis. Matlab and Python Programming

Hello, I am an Electrical Engineering Student currently working on my thesis. Our thesis is about using machine learning in line fault detection. My concern is that we want to use synthetic datasets simulated in Matlab using IEEE 13 Node Test Feeder. Is there any rule of thumb that I need in order for our machine learning algorithm to read it properly. I’ve tried to use a simulated data, however, the machine learning gave us an output of 100% in every metrics like accuracy, recall, precision, and f1 score. Our main objective is to compare 5 different machine learning algorithm and to see which one is better in such tasks. Thanks for the advice!

reddit.com
u/hatdognfriends — 6 days ago
▲ 3 r/matlab+3 crossposts

fitglm MATLAB

Hey zusammen!
Ich möchte ein Generalized linear mixed effects model mit einer logic link Funktion aufstellen, um meine Daten auszuwerten.
Ich habe folgendes Modell aufgestellt und in MATLAB eingegeben:

fitglme(Data, [y ~ x1 * x2 * x3 + (1+ x1 + x2 + x3 | u)], Distribution, binomial, Link, logit, FitMethod, Laplace);

Y ist meine binäre AV,
X1, x2 und x3 Faktoren (x1 kontinuierlich und die anderen kategorial),
U ist mein Random Effekt (Personen).
Zudem wurden die Daten mit within Subjekt und mit messwiederholung erhoben.
Jeder Proband hat jede Bedingung 10 mal gemacht.

Dieses Modell ist das komplexeste welches hier noch konvergiert und es ist auch signifikant besser als ein einfacheres Modell mit nur einem random slope für x1.
Also eigentlich passt es gut zu meinen Daten.

Ich bin allerdings neu mit LMEM und bin mir nun unsicher, was genau mein Modell nun schätzt:
Zum einen die fixen Effekte der Faktoren x1, x2 und x3 auf mein Kriterium y. Zudem alle Interaktionseffekte dieser fixen Faktoren.

Außerdem noch zufällige intercepts für jede Untergruppe von u.
und dann auch noch zufällige slopes in jedem der fixen Effekte für jedes u.

Also kann jedes U nun einen eigenen intercept haben und auch einen eigenen slope für jeden der fixen Effekte.

Aber was ist mit den interaktionseffekten?
Habe ich hier auch Interaktionen zwischen den random slopes, sodass eine höhere Steigung von u1 in Haupteffekt x1 dazu führen kann dass die Steigung von u1 in x2 geringer wird??

Und gibt es jetzt auch random slopes für die Interaktionseffekte der fixen Effekte, weil ich diese ja auch geschätzt hatte: so dass u1 auch einen eigenen slope für die Interaktion von x1 und x2 hat?

Bitte entschuldigt wenn das total wirr klingt! Ich bin da gerade ein wenig überfordert 🙈

Danke für jegliche Hilfe!

reddit.com
u/Mikuh_00 — 6 days ago
▲ 6 r/matlab

Matlab-Simulink-ROS2 with Claud ai

Hallo everyone.

i was scrolling in the internet and i saw a lot of new things about claude ai and how you can build agent or using Plugins to help you while you are working on your project and i was wondering if there is any plugin or agent that could help me out in my project. as you know the people and also the companies are willing to use more AI to build new project faster and better.

I am using at moment for my project Matlab-Simulink with ROS2 to be able to connect the robot and make it move. (i know it might be not the best combo for the project but its for a research 😄)

do you guys know any plugin or agent that i can use to support me in my project?

I would be happy for all kind of answers 😃

reddit.com
u/Individual-Public-24 — 6 days ago
▲ 33 r/matlab

Home License - Insane Value

I haven't renewed my Home license for about 18 months - mainly because I don't like the new UI. But I am doing something at home that the Optimization Toolbox would be helpful for.

So I went to have a look at renewing - and when did they do this!

https://preview.redd.it/8kt6jiw8cu0h1.png?width=982&format=png&auto=webp&s=bcb395470f573b44c4cadc4a916ac48849d11b70

I mean, when it was £85 for MATLAB and £25 to a toolbox (i think) it was already good value. But now it's a no brainer.

I had a handful of those Toolboxes already.

I've now got a real problem - my home license will be way better toolbox'ed than the work license!

Many thanks to the enlightened souls at Mathworks for this. I will be putting my MATLAB socks on today, I might go full fanboy and wear the T-shirt too 😉

reddit.com
u/Imaginary_Data_708 — 9 days ago
▲ 3 r/matlab

[Academic integrity] Can a PDF exported from MATLAB (and not subsequently modified) ever have "PSPDFKit" for "PDF Producer"?

This past semester, I gave students homework assignments whose completion requirements included creating or modifying .mlx files, running them, exporting a PDF, and submitting that PDF electronically. I suspect that some of the submissions were created in a way that did not comply with course policy, in one fashion or another, and have noticed that the metadata (as viewed using "Document Properties" in Acrobat) for some of these include "PDF Producer: PSPDFKit." I'm not familiar with PSPDFKit, but a bit of googling suggests a couple different possible uses that would be out of compliance. So I wanted to check: Is there any plausible set of conditions (e.g., the right combination of MATLAB version, OS, OS version, and other software installed) under which MATLAB could export a PDF with that property?

reddit.com
u/Excellent_Cress_3749 — 8 days ago
▲ 4 r/matlab

Need Help with MATLAB Video Analysis Assignment (shuttle.avi) – Frame Processing & Pixel Masking

Hi everyone,

I am working on a MATLAB image/video processing assignment based on the sample video file shuttle.avi. The task involves:

  1. Finding the correct frame rate of the video
  2. Removing the final frames that switch to a different camera angle
  3. Calculating the duration of the processed video
  4. Creating a grayscale mask that isolates the nearly white rocket flame using intensity thresholding (>245)
  5. Comparing the number of true (nonzero) pixels between the first and last frames

I have already tried using VideoReader, read, readFrame, VideoWriter, grayscale conversion, and logical masking, but my answers for Questions 2–4 are still incorrect in MATLAB Grader.

I attached screenshots of:

  • the assignment instructions
  • my current outputs
  • the errors/incorrect results I am getting

Even though I have tried different results outputs to complete this assignment using different MATLAB codes, all answers for Questions 2-4 are still incorrect.

Could someone please explain the correct approach for preprocessing the video and calculating the required values properly?

I would really appreciate any help or debugging suggestions. Thanks!

Here is the code.
% =========================================================
% QUESTION 1
% Find frame rate of shuttle.avi
% =========================================================

clc;
clear;

v = VideoReader('shuttle.avi');

frameRate = v.FrameRate

% Expected Answer:
% 30

% =========================================================
% QUESTION 2
% Remove frames from new camera angle
% Find total frames in the new processed video
% =========================================================

clc;
clear;

v = VideoReader('shuttle.avi');

frames = read(v);

totalFrames = size(frames,4)

% Keep only frames before camera angle changes
framesToKeep = 105

writerObj = VideoWriter('newShuttle.avi');
writerObj.FrameRate = v.FrameRate;

open(writerObj);

for k = 1:framesToKeep
writeVideo(writerObj,frames(:,:,:,k));
end

close(writerObj);

disp('Processed video created successfully')

% Expected Answer:
% 105

% =========================================================
% QUESTION 3
% Find duration of processed video
% =========================================================

clc;
clear;

v = VideoReader('newShuttle.avi');

durationSeconds = v.Duration

% Expected Answer:
% 3.50

% =========================================================
% QUESTION 4
% Count difference in true pixels between
% first and last frame
% =========================================================

clc;
clear;

v = VideoReader('newShuttle.avi');

% Read first frame
firstFrame = read(v,1);

% Read last frame
lastFrame = read(v,105);

% Convert to grayscale
firstGray = im2gray(firstFrame);
lastGray = im2gray(lastFrame);

% Create masks
firstMask = firstGray > 245;
lastMask = lastGray > 245;

% Count true pixels
firstPixels = nnz(firstMask);
lastPixels = nnz(lastMask);

differencePixels = lastPixels - firstPixels

% Expected Answer:
% 2228

% =========================================================
% EXTRA CODE
% Display all frames near camera-angle change
% =========================================================

clc;
clear;

v = VideoReader('shuttle.avi');

frames = read(v);

figure;

for k = 100:121
subplot(3,8,k-99)
imshow(frames(:,:,:,k))
title(num2str(k))
end

https://preview.redd.it/73hzirrfwg0h1.png?width=846&format=png&auto=webp&s=fc6f044172126aeb0f87d1d34158d85516400de0

Question number 1's answer is the only answer that is right. The answer is 30 FPS.

https://preview.redd.it/2ayfqjlnwg0h1.png?width=855&format=png&auto=webp&s=4243570786bcdbaeb35cd15906d1187150c973bf

reddit.com
u/Mohammad_Jawad_009 — 11 days ago
▲ 6 r/matlab

I Wish Simulink Allowed Us To Simulate ICs Too

Hello all,

I have been using Matlab and simulink since I started college and I really like it, even with little frustrations like connecting simscape and simulink sometimes.

So, recently, I’ve been doing PCB projects and been doing simulations. For example, using LTC4070 or CD4017B, I use LTSpice for these and I so dislike LTSpice. Honestly, it’s made me more appreciative of simulink. It feels unintuitive and janky.

I was just thinking that if simulink allowed blocks that you can just input datasheet parameters, it will be so great.

Or is there a way to do this and I just don’t know? If there is, please share.

reddit.com
u/Kalex8876 — 12 days ago
▲ 6 r/matlab+1 crossposts

How to Simulate Our Specific Cell in Simscape Battery builder (That is NOT In the Preset Options)

So our team is in the beggining stage of planning the battery for the TSAC. We want to simulate different cell models before we decide which one to purchase.

Our current pick is the Molicel 21700 P42B. As I was starting to build the module in the Simscape Battery builder, I noticed it wasn't included as one of the available presets of the software.

How can I use the Battery builder to simulate a battery with a cell that is not included in the presets?

I've tried using Gemini to guide me through the process, and it told me to get the data for the Battery (table base) block.

What is the Battery (table base) block? And what data do I need to include in it? And where do I find it?

note: I did download the cell data sheet from the official Molicel website, yet I'm not sure if it helps me or not.

reddit.com
u/Plenty-Quality3567 — 11 days ago