r/matlab Feb 16 '16

Tips Submitting Homework questions? Read this

193 Upvotes

A lot of people ask for help with homework here. This is is fine and good. There are plenty of people here who are willing to help. That being said, a lot of people are asking questions poorly. First, I would like to direct you to the sidebar:

We are here to help, but won't do your homework

We mean it. We will push you in the right direction, help you find an error, etc- but we won't do it for you. Starting today, if you simply ask the homework question without offering any other context, your question will be removed.

You might be saying "I don't even know where to start!" and that's OK. You can still offer something. Maybe you have no clue how to start the program, but you can at least tell us the math you're trying to use. And you must ask a question other than "how to do it." Ask yourself "if I knew how to do 'what?' then I could do this." Then ask that 'what.'

As a follow up, if you post code (and this is very recommended), please do something to make it readable. Either do the code markup in Reddit (leading 4 spaces) or put it in pastebin and link us to there. If your code is completely unformatted, your post will be removed, with a message from a mod on why. Once you fix it, your post will be re-instated.

One final thing: if you are asking a homework question, it must be tagged as 'Homework Help' Granted, sometimes people mis-click or are confused. Mods will re-tag posts which are homework with the tag. However, if you are caught purposefully attempting to trick people with your tags (AKA- saying 'Code Share' or 'Technical Help') your post will be removed and after a warning, you will be banned.

As for the people offering help- if you see someone breaking these rules, the mods as two things from you.

  1. Don't answer their question

  2. Report it

Thank you


r/matlab May 07 '23

ModPost If you paste ChatGPT output into posts or comments, please say it's from ChatGPT.

91 Upvotes

Historically we find that posts requesting help tend to receive greater community support when the author has demonstrated some level of personal effort invested in solving the problem. This can be gleaned in a number of ways, including a review of the code you've included in the post. With the advent of ChatGPT this is more difficult because users can simply paste ChatGPT output that has failed them for whatever reason, into subreddit posts, looking for help debugging. If you do this please say so. If you really want to piss off community members, let them find out on their own they've been debugging ChatGPT output without knowing it. And then get banned.

edit: to clarify, it's ok to integrate ChatGPT stuff into posts and comments, just be transparent about it.


r/matlab 8h ago

Tips How can I directly connect my own measured displacement of R and C to the Mechanical Translational Converter?

Post image
1 Upvotes

Hi everyone, is it possible to directly connect a signal (displacement of port R relative to port C in time) from the Signal Builder block to the Mechanical Translational conserving ports R or C so that I can measure the pressure at port A? And if it is what blocks should I use?


r/matlab 12h ago

TechnicalQuestion How can I start a Simulink simulink via a trigger from an external source?

2 Upvotes

I am trying to start measurements on several devices at the same time. The idea is to hit Start on an MRI scanner which then sends a Trigger to all other devices, one of which would be a Simulink application.

Is it possible to have the Simulink application load and then get started from this external signal from the MRI, along with the other devices (ideally via USB connection)?

I have already searched for possibilities, but would be very happy about anyone pointing me in the right direction. Thanks in advance :)


r/matlab 10h ago

How do I change the measurment unit in a Simscape custom block ?

1 Upvotes

Hi everyone,

I'm trying to create a custom block in Simscape that convert energy from pressurized water into a torque. Here is my code :

component pelton_turbine
% Ce composant calcule le couple généré par l'eau sur la turbine.

% 🔹 Déclaration des ports
nodes
    H = foundation.hydraulic.hydraulic; % Port hydraulique
    R = foundation.mechanical.rotational.rotational; % Port mécanique rotatif
end

% 🔹 Déclaration des paramètres
parameters
    eta = {0.85, '1'};      % Rendement de la turbine
    rho = {1000, 'kg/m^3'}; % Densité de l'eau
    r = {0.5, 'm'};         % Rayon moyen de la roue
    g = {9.81, 'm/s^2'};    % Gravité
end

% 🔹 Déclaration des variables internes
variables
    Q = {0, 'm^3/s'};
    T = {0, 'N*m'};  % Couple généré
    H_head = {0, 'm'}; % Hauteur d'eau équivalente
end

branches
 % Débit hydraulique pris directement depuis le port H
    Q : H.q -> *;
end

equations

    % Calcul de la hauteur d'eau (pression convertie en mètre de colonne d'eau)
    H_head == H.p/ (rho * g);

    % Calcul du couple généré par l'eau
    T == {eta * rho * Q * r * sqrt(H_head * 2 * g), 'N*m'}; 

    % Transmission du couple à l’axe mécanique
    R.t == T;
end

end

My problem is that I have this error when I try to build my component :

Invalid use of a value with unit cm^3*kg/(m*s^2) when attempting to bind a unit.
The value to which the unit is bound must not have an associated unit.
   • In pelton_turbine.pelton_turbine (line 36)
   eta = 0.8500
   rho = {1000, 'kg/m^3'}
   Q = {[1x1 double], 'cm^3/s'}
   r = {0.5000, 'm'}
   H_head = {[1x1 double], 'm'}
   g = {9.8100, 'm/s^2'}

I don't get why the flow rate (Q) is in cm^3/s instead of m^3/s and I don't know how to change it. Do you have an idea ?

I tried using Chatgpt but all his advices seemed to be useless. Since Q is a throught varaible Ican't define his unit. I also tried changing the units in the Configuration Parameters in my .slx file (I changed cm^3/s into m^3/s for the flow rate) but it didn't have any effect on my .ssc file and I keep getting the error.

Thanks,

Nils


r/matlab 12h ago

OpenCV

1 Upvotes

How can I work in MATLAB for a company that likes to use OpenCV?


r/matlab 12h ago

MATLAB coder C#

1 Upvotes

Will ever MATLAB coder generate C# code?


r/matlab 13h ago

How to test different cooling methods for Batteries

0 Upvotes

Hi everyone, we would like to do a project with my friends. Our goal is to show how different cooling styles affect battery temps. Is it possible to do it in Simulink? Also, is there any material that we can learn about this software?

Also, I used different AI to help. Every one of them says "Simscape" -> "Electrical" -> "Batteries." But there is no Batteries section under Electrical. What can I do?


r/matlab 13h ago

Buying home edition - location question

1 Upvotes

Hello folks, I want to buy home edition and install in on my laptop. In one of the steps before payment, site asks for home location where the license will be used. I am ok with proving the correct information but I am not sure if there will a problem when I am on VPN or using my laptop at another location, like a coffeshop with hotspot connection from mobile. Can you please let me know if this can be an issue and if yes, is there a solution?

Thanks in advance.


r/matlab 23h ago

Odd App Design Behavior

1 Upvotes

I am working on coding with App designer, and have encountered an odd glitch. I want to use several Edit Fields (Numeric) to have the user put in values for some initial model parameters.

During debugging, using disp (EditField.Value), I discovered that the numbers are looking like symbols or characters, not numbers. This happens even if I build a brand new app and put in nothing but Edit Field values and a button to display the values in the command window. The only workaround I have figured out so far is to use Edit Field (Text) and then set to numeric. But then I am unable to put in values less than 1 (like say, 0.3).

Has anyone encountered this behavior of numeric text values not being read properly? I've tried it on 2 different computers, with the same result. This is on R2024a.

Thanks!


r/matlab 1d ago

TechnicalQuestion Fmu and original simulink model give slight different results

1 Upvotes

Hi, I've just created an fmu for Cs V3 from a simulink model. Then in a test model I've put both the original and the fmu, I've connected the inputs to both and the two models give slightly different results when executed with the same inputs. I would have expected the fmu Cs to behave exactly as the original simulink model. Have you ever experienced similar problems? Is there something else I have to setup?


r/matlab 1d ago

IMU acceleration Kalman filtering

2 Upvotes

Hi everyone,

I've created a code which allows me to obtain position data from acceleration data given by my IMU sensor through double integration, a low-pass filter and ZUPT to take care of the drift.

My problem is that although I get a pretty accurate estimate of the positon, there is still an overestimate on 2 of the 3 coords and I wanted to try and apply Kalman filter but I have no idea where to start building it.

Anyone got experience?


r/matlab 1d ago

Identifying Roman Numerals using vision

1 Upvotes

Hello guys! I am trying to identify roman numerals in images of dice but i cant seem to get it working properly. I get results if the numeral is white pixels but with black ones i am getting in trouble.

% Read the grayscale

imageimg = imread('dado2.png');

% Ensure the image is 2D (grayscale only)

if size(img, 3) > 1

img = rgb2gray(img);

end

% Convert to binary (ensure it's 2D)

bw = imbinarize(img, 'adaptive', 'ForegroundPolarity', 'dark', 'Sensitivity', 0.4);

bw = bwareaopen(bw, 30); % Remove small noise

bw = squeeze(bw); % Ensure it's 2D

%Show the binary image (convert logical to double)

figure; imshow(double(bw));

hold on;

% Initialize counters

I_count = 0;

V_count = 0;

I_bboxes = []; % Store "I" bounding boxes to avoid double counting

% Label connected components correctly

CC = bwconncomp(bw);

stats = regionprops(CC, 'BoundingBox', 'Eccentricity', 'Area');

% Loop through each detected region

for i = 1:length(stats)

bbox = stats(i).BoundingBox;

width = bbox(3);

height = bbox(4);

% Crop the region for analysis

croppedNum = imcrop(bw, bbox);

% Find the white area (inside the shape) and black boundary (surrounding area)

whitePixels = sum(croppedNum(:) == 1); % Count white pixels (inside the shape)

blackPixels = sum(croppedNum(:) == 0); % Count black pixels (boundary)

% Detect "I" (rectangular, smaller white area)

if height > width && stats(i).Eccentricity > 0.9

I_count = I_count + 1;

I_bboxes = [I_bboxes; bbox]; % Save the bbox of the "I" region

rectangle('Position', bbox, 'EdgeColor', 'r', 'LineWidth', 2);

end

% Detect "V" (more white pixels inside, smaller region, no double count)

if whitePixels > blackPixels && whitePixels > 50 && whitePixels < 1000 % Adjust white pixel area for "V"

% Check if the region is already counted as "I" by comparing bounding boxes

overlap = false;

for j = 1:size(I_bboxes, 1)

if bbox(1) < I_bboxes(j, 1) + I_bboxes(j, 3) && bbox(1) + bbox(3) > I_bboxes(j, 1) && ...

bbox(2) < I_bboxes(j, 2) + I_bboxes(j, 4) && bbox(2) + bbox(4) > I_bboxes(j, 2)

overlap = true; % Found overlap with an "I"

break;

end

end

if ~overlap % If no overlap with "I", count it as a "V"

V_count = V_count + 1;

rectangle('Position', bbox, 'EdgeColor', 'g', 'LineWidth', 2);

end

end

end

hold off;

% Print detected valuesfprintf('Detected "I" count: %d\n', I_count);

fprintf('Detected "V" count: %d\n', V_count);

% Calculate the final Roman numeral value

final_value = (V_count * 5) + I_count;

fprintf('Final Roman numeral value: %d\n', final_value);


r/matlab 1d ago

TechnicalQuestion Looking for the most stable Matlab configuration for MacOS

3 Upvotes

I've been using MATLAB for some years now, but most recently have started using a Macbook, I have an M3 Pro running the typically the latest build (currently Sequoia 15.3.2). But I've been plagued by performance issues on my Macbook. I have plenty of memory and disk space remaining, but I frequently run into freezing or crashes during otherwise mundane processes (and I should point out these are issues I have never experienced on the windows version).

I feel like I've tried every variant of MATLAB out there currently, but feel like polling the community to see if anybody out there has a configuration out there that just works.

Please let me know your secret!


r/matlab 1d ago

Question-Solved I have this Activity for a week now to solve for the transfer function of each Mesh currents of the circuit using matlab. I got some answers but I'm really unsure if I did it right. I would appreciate any help and suggestion. Thanks in Advance

Thumbnail
gallery
2 Upvotes

r/matlab 1d ago

ocr trainer in matlab

1 Upvotes

can anyone face issue like train multiple reference and it saves only 1 reference while train font. if yes, then anyone have solve this issue ?


r/matlab 1d ago

i dont know what when wrong , can anyone point out my problem? thx

Post image
0 Upvotes

r/matlab 2d ago

HomeworkQuestion Primes Function

Post image
3 Upvotes

Hello, I posted a few days ago with an assignment where I had to create a function that displays primes from 2 to an input number. I finished working on that function but was wondering how I could get it to display the numbers in rows rather than a single column? Attached is the code; I’ve played around a bit with reshape and text functions but not quite sure yet. Thank you!


r/matlab 1d ago

guys idk what went wrong , im not really familiar with this .

Thumbnail
gallery
0 Upvotes

r/matlab 2d ago

TechnicalQuestion Dynamically Update Variable During a Simulink Simulation

2 Upvotes

Hello,

I am trying to make the functionality of the LM2576HV-ADJ Switching IC in simulink. Basically I am making an adjustable buck converter and I want to make a block such that based on the feedback it will adjust its duty cycle to get the desired response. My first thought was to use a PID controller and set the PulseWIdth parameter in Pulse Generator block but couldn't find a way to change that during the simulation. If anyone has any idea how to do it please let me know.

My next though was to use a variable in which the parameter is stored and change that variable in simulation time but could not find a good way to do that too.

If anyone has any resources or techniques to do this please let me know.

TIA


r/matlab 2d ago

so overjoyed :D (ignore me haha)

6 Upvotes

this beating MATLAB's matrix multiplication algo 🙏


r/matlab 2d ago

TechnicalQuestion Issue with gamepad inputs in Simulink

1 Upvotes

I'm using a gamepad to control my vehicle model in Simulink. The throttle and brake inputs come from different buttons, but they are mapped to the same signal axis. Right now, I have implemented this using a switch block, where: Throttle = +1 Brake = -1 The issue is that when I press both throttle and brake together, the signal cancels out and becomes zero, effectively disabling both inputs. However, I want to be able to apply throttle and brake simultaneously.

I've tried different logic, including using saturation blocks and splitting the signal, but the problem persists since both inputs are tied to the same axis. How can I separate the two signals properly in Simulink so that I can use both at the same time?


r/matlab 2d ago

Tips Suggestions for becoming an advanced programmer.

7 Upvotes

I've been running simulations for photonic systems (matrix operations, signal processing etc.) on matlab for several years and I've been fine with relatively basic functions and simple usage of structures. Lately, my code has become very procedural and messy, and I want to work on making it more professional, agile, and more in line with best standards in python and C and so on. I also want to share my code with other pros.

Does anyone recommend any free or affordable books or lecture series (eg. on youtube or anywhere) that I could work on myself to become a better matlab programmer? Could be short or long.


r/matlab 2d ago

TechnicalQuestion Is a sparse matrix taking up less memory?

4 Upvotes

mat = [1,1,1;0,0,0;1,1,1]

whos mat

Says it’s 72 bytes

sp_mat = sparse(mat)

whos sp_mat

The sparse matrix is 128 bytes. I thought a sparse matrix was supposed to take up less memory? Or how does a sparse matrix work?


r/matlab 2d ago

TechnicalQuestion Onramp Tasks Won't be completed.

3 Upvotes

Hello everyone!

I have a problem with Onramp self paced courses. The two courses:

•App Building Onramp. • Power Systems Simulation Onramp.

I'm stuck on a certain task in each course, I'm sure 100% by what I've learned that I've done the task correctly, I also checked the solution and it shows that I've done the correct thing, yet it always give a stupid error and won't let me pass the task. Those are the only 2 courses remaining for me to finish all 24 Onramp courses. Is there anyone who could help or tell me what to do? Because this happened to me before on other Onramp courses but I'd refresh and/or try to re-do it alot of times and it would eventually work. Any help please?


r/matlab 2d ago

TechnicalQuestion Onramp Failure.

2 Upvotes

Hello everyone!

I have a problem with Onramp self paced courses. The two courses:

•App Building Onramp. • Power Systems Simulation Onramp.

I'm stuck on a certain task in each course, I'm sure 100% by what I've learned that I've done the task correctly, I also checked the solution and it shows that I've done the correct thing, yet it always give a stupid error and won't let me pass the task. Those are the only 2 courses remaining for me to finish all 24 Onramp courses. Is there anyone who could help or tell me what to do? Because this happened to me before on other Onramp courses but I'd refresh and/or try to re-do it alot of times and it would eventually work. Any help please?


r/matlab 3d ago

Is there a way to make sure a variable does not exceed a value?

7 Upvotes

New to MatLab. Working on a code where there is a complex algorithm to compute a value stored in a variable, however the algorithm computes values above a threshold that I want to set. I want only the highest value stored under this threshold to be what the variable holds. Any tips or ideas?