/r/matlab
Official MATLAB subreddit
MATLAB news, code tips and tricks, questions, and discussion! We are here to help, but won't do your homework or help you pirate software.
The effort you put into asking a question is often matched by the quality of our answers.
Try saturnapi to share and run MATLAB code in a web browser!
If you want flair simply Message the mods
/r/matlab
Hi everyone,
I am trying to do the following computations but my matrices are very large (over 6.000.000 lines) and as you can imagine it takes ages and at some point I get an out of memory error. More precisely, for each Director in my BEorg_sum_us table I want to find the number of previous Roles that he had from the boardexindemploymentus table.
uqDiDs = unique( BEorg_sum_us.DirectorID );
BEorg_sum_us.NumRoles = NaN( height( BEorg_sum_us ), 1);
tic
for i = 1:100 %numel(uqDiDs)
inds = BEorg_sum_us.DirectorID == uqDiDs(i);
tmp = BEorg_sum_us( inds, :);
tmpEmpl = boardexindemploymentus( ismember(boardexindemploymentus.DirectorID, uqDiDs(i) ), : );
numRoles = nan( height(tmp), 1);
if ~isempty(tmpEmpl)
for j = 1:height( tmp )
roles = tmpEmpl( tmpEmpl.StartYear < tmp.AnnualReportDate(j), 'Topics' );
numRoles(j) = height( unique( roles ) );
end
BEorg_sum_us.NumRoles(inds) = numRoles;
end
end
toc
This approach I estimate that it need about 6 hours.
I have tried to cast everything inside the for loop into a function and then use parfor but I get the out of memory treatment.
uqDiDs = unique( BEorg_sum_us.DirectorID );
BEorg_sum_us.NumRoles = NaN( height( BEorg_sum_us ), 1);
NumRoles = cell( height( uqDiDs ), 1);
tic
for i = 1:100 %numel(uqDiDs)
NumRoles{i} = functionalRoles(BEorg_sum_us, boardexindemploymentus, uqDiDs(i) );
end
for i = 1:100
inds = BEorg_sum_us.DirectorID == uqDiDs(i);
BEorg_sum_us.NumRoles(inds) = NumRoles{i};
end
toc
As a final approach I have tried to use a tall array for boardexindemploymentus whihc is over 6000000 lines but it take about 4-5 minutes for one iteration. In the above example I run it for the first 100 uqDiDs but I have around 140.000.
Any help to reduce computation time and optimise memory usage is much appreciated! Thank you in advance.
Idk what happened but after deleting some callback functions in app design, the selection of ButtonDownFcn is missing in buttons and only ValueChangedFcn is available. I tried reinstalling but nothing changed. How do I make the ButtonDownFcn back again?
Edit: I also discovered that the ButtonDownFcn is only available in UI figure but not in other components
I need to create a code that rejects anything input thats not a whole number, im a beginner and in need of help asap :)
Choose your ODE type, enter the function and parameters, select an automatic or manual solver, and visualize your results.
I have open the help site, and I test the code. The code ran out badly(see in picture below).
Why stop when not train well? What is the matter? You are not helping at all! You are making it more and more confusing!! What is the deal? There is even no one that is checking the code or the example?What is going on with matlab staff?
So I am trying to convert the white image of a graph in which x-axis is engine RPMs and y-axis is torque. The curves are isolines for different engine efficiencies. I have two problems:
The approach I am following is:
Thanks in advance.
img = imread('graph1.jpg');
grey_img = rgb2gray(img);
binarized = imbinarize(grey_img);
%thin_curves = bwmorph(binarized, 'thin', inf);
thin_curves = binarized;
xmin = 1100;
xmax = 7500;
ymin = 0;
ymax = 300;
data = zeros(1, 2);
indx = 1;
for i = 1:size(thin_curves, 1)
for j = 1:size(thin_curves, 2)
if thin_curves(i, j) == 0
data(indx, 1) = j * (xmax - xmin) / size(thin_curves, 2) + xmin;
data(indx, 2) = i * (ymin - ymax) / size(thin_curves, 1) + ymax;
indx = indx + 1;
end
end
end
So I have a Problem where I need to scale the x-axis by a factor while also setting a specific x-value instead of the one in my data (Excel sheet).
I hope you understand what I am trying to day.
Does anyone know how to do this?
Is there any course available to learn MATLAB Simulink for free
hello guys, i am implementing the network shown on the frist image using simevents in matlab simulink. it consists of five machines and buffers in between them. in the second picture is my current implementation( you ddont have to focus on all of these). my problem is in the assembly nd disassembly processes. the article that describes the network says the following about those processes: the transfer line module includes a machine Mi which takes unfinished items from an upstream buffer Bj,i and after processing, sends them to a downstream buffer Bi,l (Fig. 1(a)). The assembly operation is presented in Fig. 1(b). A machine Mi obtains two or more parts or subassemblies, following an assembly factor δj,i from more than one upstream buffers Bj,i, brings them together to form a single unit, which is sent to a downstream buffer Bi,l. The disassembly operation involves a machine Mi taking unfinished single units from one upstream buffer Bj,i, separates them to two or more parts or subassemblies following a disassembly factor di,j, and sends them to downstream buffers Bi,k, as shown in Fig. 1(c). i cant figure out how to implement those with the current blocks simevents has available. i need to define some fixed assembly and disassembly factors , any ideas?
.
Hey,
i have an exercise that i just cant figure out.
"In aviation, hydraulic systems are used, for example, to control the flight control surfaces, high-lift devices and landing gear of an aircraft. Below is a simplified hydromechanical system that extends and retracts a flap of an aircraft. The control signal of the directional valve is ±10 V and the stroke of the hydraulic cylinder 1.4 m. Open the Simulink template and build an open loop controller that’s connected to the unit delay block leading to the valve actuator. For take-off the flaps are set in the middle position and then retracted afterwards. Tune the controller so that the cylinder performs the same movement as in the figure below as closely as possible."
In the pic there's a cylinder target position graph. From 0-4 secs it stays at 0, from 4 to 6 seconds it goes to 0.7 m and stays at it until 14 seconds. From there it goes back to 0 at 16 seconds.
Picture of the simulink model given.
Hello. I have a Matlab assignment on telecommunication engineering. I tried to ask it in chegg.com, but unfortunately their codes didn't work at all. Is there any trustworty website that I can ask my assignment?
Hi, when I try to run this code, it will not run. I asked my professor about it on Wednesday at the very end of our last class and if I remember correctly, she said it had something to do with HW4, but I can't remember what.
The error is
Unrecognized function or variable 'ptm'.
Error in HW6_loadCTDcchdo (line 56)
raw.ptm = ptm(raw.tem, raw.prs);
Can someone please help me figure this out? I am about to leave for work so I will not be able to respond to any comments until 7:30 if I need to give follow up information. Thank you.
The first four pictures are the current HW and the last one is a picture of the PDF of HW4.
EDIT: Sorry, I dont use my laptop for reddit usually, here are the pictures! Thank you again!
for a university project i am supposed to import a 3D model into matlab, i have all the step files and xml files and code for the matlab assembly i just dont know how to import it. I found information on using smimport but i dont think thats my case. Anyone got any tips?
Hi I am trying to link two files, Ybus.m and Jacobian.m into my matlab code.
This is the code I am trying to run:
clear alladdpath('C:\Users\sabri\OneDrive\Documents\ECE6320');
which Jacobian.m
which Ybus.m
Jacobian; % File from PW, includes the sparse Jac
YBus; % File from PW, includes Ybus and V variables
I defined the path specifically and when I run which it points to the correct file. However when I just try to actually pull up the Jacobian or Ybus values themselves the program doesn't recognize the variables. I've verified that both files have the correct inputs in them. However when I open the Jacobian file in Matlab I get this error
Does anyone know how to fix this and link properly?
I am trying to inspect the velocity profile of a half-car model on Simulink when subjected to bumpy road conditions. I can somehow figure out the half-car model, but I have no clue how to introduce road bumps as input.
Is it possible to use a real-world dataset of rough terrain as excitation input to the model?
any kind of advice is appreciated.
Sorry for the inconvenience.
Specs:
CPU: i5
GPU:RTX 4060
MATLAB works very slow. takes way long to load and opening other layouts and add ins takes way to long.
Hi,
I am a second-year student, and I have to do a MATLAB project as homework for my university. I have several ideas, but I haven’t decided yet.
1. Football Match Bet Analysis
2. Image Compression
3. Real Estate Price Analysis
4. Stock Price Prediction
5. Portfolio Optimization
Actually, all of them interest me. By improving this project, I can learn data analysis or machine learning skills. What do you think about these projects? Which one would be the most beneficial?
I have a standalone application from MATLAB app designer, and was wondering if there is any compiler that can produce installation files for mac systems.
I am struggling to work out the solution to this tutorial question using matlab. Any help would be greatly appreciated. F1 and F2 are forces with magnitudes 8 N and 10 N, respectively. They act on a particle located at the origin.
The force F1 acts in the positive horizontal direction, the force F2 is inclined at an angle of 30◦ (counter-clockwise) with respect to F1.
Define F1 and F2 in 2D Cartesian components (e.g. F1 = [F1_x, F1_y], F2=[F2_x,F2_y]), assign them to MATLAB variables F1 and F2.
Determine the resultant force R acting on the particle:
the vector of the R in Cartesian form, e.g. R=[R_x,R_y]
the magnitude of the resultant force R, assign it to the MATLAB variable R_abs. DO NOT USE norm() FUNCTION of MATLAB.
the angle (in degrees) of the resultant force R with the positive direction of x-axis, assign to the MATLAB variable theta.
n = 120;
x1 = [0:2pi/120:2pi];
x2 = linspace(0, 2*pi, n+1);
if (x1 == x2)
disp("equal")
else
disp("no")
end
Output: no
Why don't these methods yield the same output?
I’m studying chem eng and we started matlab and i realized it would be hard for me to pass without any external help
Hi. I am trying to convert my Matlab algorithm to C-code using the Matlab Coder application. One step in the algorithm is using the wavelet transform and reconstructing the signal with Matlab’s “wrcoef” function for a specific detail level. The problem is that this function can’t be used with the Matlab Coder. I have tried other methods for reconstruction like Matlab’s “waverec” function, but the reconstruction output is different than that with the “wrcoef” function. Does anyone have a work around to get the output of the “wrcoef” function and make it compatible with the Matlab Coder application?
the figure above is results of my simulink output for angular displacement. but the state space is diverging away. this is the equation [(𝑚1 + 𝑚2 ) ∙ 𝑙1 2 ∙ ddot𝜃1 + (𝑚1 + 𝑚2 ) ∙ 𝑙1 ∙ 𝑔 ∙ sin(𝜃1 ) = T], how can i linearize this in state space representation?
also examiner says that: Note: To create the state space, you will need to linearize the system. Use the condition of small angles, i.e. the sine of a small angle can be considered as the angle itself (𝑠𝑖𝑛 𝜃1 ≈ 𝜃1 𝑖𝑓 𝜃1 𝑖𝑠 𝑠𝑚𝑎𝑙𝑙). i did this but no good result as you can see in the figure
I wanted to design an 8:1 LVDS SerDes in Matlab using SerDes Designer tool( please suggest if there's any other better method) , what's the flow of the design process and is there any beginner friendly material to understand the flow of the design