Risposto
Sorting two simple matrices
Use the 2nd output argument of the sort( ) function, which has the indexing. E.g., [Asorted,ix] = sort(A); Bsorted = B(ix);

oltre 5 anni fa | 1

| accettato

Risposto
Preserving numerical symmetry in large nxn matrix
Why do you think L should be symmetric? E.g., (1) L = D^-1 * W * D (2) L^T = (D^-1 * W * D)^T = D^T * W^T * (D^-1)^T = D * W ...

oltre 5 anni fa | 0

Risposto
Error in ODE45, must return a column vector
Just make your function handle return a column vector by using ; instead of , to separate the elements. E.g., ode = @(Qhat,X) [...

oltre 5 anni fa | 0

Risposto
How to Solve 13 ODEs simultaneously by ode45
Your c0 has only 12 elements. It needs to have 13 elements.

oltre 5 anni fa | 0

Risposto
How to generate double pendulum using ode 45
You have a 4-element state vector, so your derivative needs to be a 4-element state vector. E.g., dxdt=[theta1dot;theta2dot;th...

oltre 5 anni fa | 0

Risposto
Help with arrays please
I'm not sure what the question is. Just enter the text as shown to create the 2x2 matrix A: A = [-10 -9; -8 6]; ...

oltre 5 anni fa | 0

Risposto
How to calculate mean to an equal area in Matlab?
n = 3; % or whatever number of samples you need, must be divisible into size of data time_average = mean(reshape(time_data,n,[]...

oltre 5 anni fa | 0

| accettato

Risposto
What code should I use to be able to solve these MatLab questions?
Hint #1: Here is sample syntax to use to create a 2x4 matrix Q = [1 2 3 4; 5 6 7 8] Hint #2: See the following function for s...

oltre 5 anni fa | 0

Risposto
How to divide a vector randomly in 3 groups?
Maybe a simple loop: n = numel(A); n10 = floor(0.10*n)-1; n80 = floor(0.80*n); for k=1:3 k1 = randi(n-n10); k2 = k...

oltre 5 anni fa | 0

Risposto
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...

oltre 5 anni fa | 1

| accettato

Risposto
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.

oltre 5 anni fa | 0

| accettato

Risposto
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...

oltre 5 anni fa | 2

Risposto
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 ...

oltre 5 anni fa | 1

Risposto
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 ...

oltre 5 anni fa | 0

| accettato

Risposto
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...

oltre 5 anni fa | 1

Risposto
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...

oltre 5 anni fa | 0

Risposto
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...

oltre 5 anni fa | 1

| accettato

Risposto
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...

oltre 5 anni fa | 0

| accettato

Risposto
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.

oltre 5 anni fa | 0

| accettato

Risposto
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...

oltre 5 anni fa | 0

| accettato

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

oltre 5 anni fa | 1

| accettato

Risposto
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 ...

oltre 5 anni fa | 0

Risposto
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...

oltre 5 anni fa | 4

Risposto
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...

oltre 5 anni fa | 2

| accettato

Risposto
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[...

oltre 5 anni fa | 0

| accettato

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

oltre 5 anni fa | 0

| accettato

Risposto
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 ...

oltre 5 anni fa | 1

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

oltre 5 anni fa | 1

| accettato

Risposto
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...

oltre 5 anni fa | 1

| accettato

Risposto
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...

oltre 5 anni fa | 0

| accettato

Carica altro