Answered
Replacing for loops with vectorization
No, in general you cannot vectorize loops such as this. What you are doing in this particular loop is solving a 2nd order diffe...

5 years ago | 1

| accepted

Answered
changing loop index within the loop
If you need to modify the loop index within the loop, use a while-loop instead of a for-loop.

5 years ago | 0

| accepted

Answered
Matrix Multiplication & Splitting
Based on your latest posts, it sounds like you really want A*C(3x3 slice)*B. So again it would be nice to do all the multiplies...

5 years ago | 2

Answered
Matrix Multiplication & Splitting
Your dimensions don't work. A*B is going to be 3x1. You can't multiply this by a 3xN matrix. That being said, suppose you did ...

5 years ago | 1

Answered
solving ordinary differential equation
Starting with this differential equation: m*d2xdt2 + a*(dxdt)^2 + k*x= F*cos(omega*t) The first step is to solve the equation ...

5 years ago | 0

| accepted

Answered
How to extract the expression inside of a trig function?
You could write your own simple parser for this. E.g., code for finding stuff inside the first function in the line could be: Z...

5 years ago | 1

Answered
multi-indexing (slicing) with different slice size
You would probably need to generate the linear/logical indexes of the elements involved and then you could assign all of those s...

5 years ago | 0

Answered
Trapezoid algorithm on an ODE
You need to pass the entire state to the derivative function, not just one element of the state. E.g., utmp = u(idx,:) + dt*dud...

5 years ago | 1

| accepted

Answered
Could I pass a 'triangulation' class into mex?
triangulation is a classdef OOP class. You cannot use struct API functions such as mxGetField( ) to get at the properties. You...

5 years ago | 0

| accepted

Answered
How to convert simple multiplication of variables into dot(.*) multiplication
You could use this https://www.mathworks.com/help/matlab/ref/vectorize.html although current doc says it is not recommended.

5 years ago | 0

| accepted

Answered
How to "free" or "destroy" pointer array of mxArray?
You must do each one. So mxDestroyArray(tmp[0]); mxDestroyArray(tmp[1]); mxDestroyArray(tmp[2]); or you could put these i...

5 years ago | 0

| accepted

Answered
Adjusting size of matrix when converting base 10 to binary
Specify the number of binary digits to use. E.g., dec2bin(30,8)

5 years ago | 1

| accepted

Answered
Index exceeds the number of array elements (2).
This line has y(3) dydt(2) = (2*k*uG-4*c*y(2)-2*c(y(2)-y(4))-2*k*y(1)-k*(y(1)-y(3)))/(2*m); What is the differential equation ...

5 years ago | 0

Answered
Split array into equal parts
You could reshape it and then access by columns. E.g., R = reshape(A,8,[]); Then A(:,1) is the first 8 values, A(:,2) is the s...

5 years ago | 4

Answered
Problems with Fortran MEX files with R2020b on Linux
So, the timestwo.F file that ships with MATLAB has bugs. I pointed this out to TMW several years ago, but I just checked and as...

5 years ago | 2

| accepted

Answered
How to make two mxArray* scalar multiply each other?
x and y are pointers, so you need to dereference them to get at the double values they point to. So your code should be: plhs[...

5 years ago | 0

| accepted

Answered
Extracting data form a single cell
Draw{1}(1) is the rank and Draw{1}(2) is the suit.

5 years ago | 0

| accepted

Answered
Calculating the Most Similar Pair of Vectors using Cosine distance in a matrix
Use a standard matrix multiply to get the dot products. MATLAB is very fast at standard matrix multiplies. And then normalize ...

5 years ago | 1

Answered
How do I display my output for symbolic variables after solving them?
Convert to double first. E.g., Voltage2 = ["v2 = ",num2str(double(V2Sol))];

5 years ago | 1

| accepted

Answered
How to Loop in mexfunction?
You have a fundamental misunderstanding of how the C language works with pass-by-value scalar arguments. In this code: voi...

5 years ago | 1

| accepted

Answered
Mexfunction: Undefined function or variable
Your m-code can't see C functions inside your mex routine. You need to call the mex routine by its filename, and then inside th...

5 years ago | 0

| accepted

Answered
Multiplication chart In MATLAB
You don't need R. Just multiply ii*jj. E.g., fprintf('%g ', ii*jj) There are also ways to generate this table without any fo...

5 years ago | 0

Answered
Is it possible to pass functions as arguments to C++ MEX functions?
Just quickly skimming the MATLAB C++ API doc, it looks like you can do this using the matlab::engine::MATLABEngine::feval interf...

5 years ago | 0

| accepted

Answered
Program that sums as many numbers as user wants
An outline of the code could be: total = 0; while( true ) % insert code here to get a number from the user % insert ...

5 years ago | 0

| accepted

Answered
issue using indices...maybe?
You are doing a numeric itegration to generate the plotting points. Numeric integration will build up errors over time, so the ...

5 years ago | 0

| accepted

Answered
Finding the intersect between 2 lines
If you want the intersection of two lines and you have the equations of the lines, just use backslash. E.g., if you have these ...

5 years ago | 0

| accepted

Answered
Create a concatenated matrix in matlab
Change this HMC_Kh = [HMC_Kh; H]; to this HMC_Kh(i,1:numel(H)) = H; There were two problems with your current code. The numb...

5 years ago | 1

Answered
Sign of imaginary value changes after converting to array
Here is what I get: >> a = 2 + 1j; >> b = 1 + 3j; >> z1 = a*b z1 = -1.0000 + 7.0000i >> z2 = b*conj(b) z2 = 10 >>...

5 years ago | 1

Answered
How can I plot the function y = e^(-2x^2) * cos(4pi*x - 1.5)?
Pick a range for x. E.g., x = 0:0.01:2; y = exp(-2.*x.^2) .* cos(4.*pi.*x - 1.5); plot(x,y)

5 years ago | 0

| accepted

Answered
Where in my code using runge- kutta four step method did I make a mistake?
Type the following at the command line: edit rk4singlestep.m Then copy your code into that file and save it.

5 years ago | 0

| accepted

Load more