Answered
Why do I get "Array indices must be positive integers or logical values" error when using?
k is 3.5 So y(k-1) is y(2.5) and y(k-2) is y(1.5). The indexes are not positive integers, hence the error. Maybe you meant ...

5 years ago | 0

| accepted

Answered
How to fill mxArray with mxGetComplexDoubles?
No, this would not be expected to work. In the first place, you need to use mxDOUBLE_CLASS to create the mxArray, not mxSINGLE_...

5 years ago | 0

| accepted

Answered
The spacecraft free-fall math model
See this link for an example of the parachute problem: https://www.mathworks.com/matlabcentral/answers/516385-code-not-working-...

5 years ago | 0

Answered
Satellite Orbit, Friction Acceleration Function
See this link for an example that uses atmospheric drag with a satellite (in this case a satellite falling to Earth): https://w...

5 years ago | 0

Answered
Fibonacci Series Using Recursive Function
All of your recursive calls decrement n-1. Eventually you will wind up with the input n=0 and just return v=0, which is not wha...

5 years ago | 0

Answered
How to fix error: "Index in position 1 is invalid. Array indices must be positive integers or logical values"
Type the following at the command line: dbstop if error Then run your code. When the error occurs, the code will pause with a...

5 years ago | 0

| accepted

Answered
Why do I get this error message "Array indices must be positive integers or logical values."
You forgot to multiply between the y and (y-1) Z = x(:).^2.*y.*(y-1).*(y+1); Also, make sure to use element-wise operators (wi...

5 years ago | 0

Answered
pointers in object-oriented matlab programing
MATLAB does not have variable pointers ... at least not in the sense of C/C++ like you are probably alluding to.

5 years ago | 0

Answered
Recursion in matrix calculation
This uses recursive calls (CalDet calls CalDet with smaller matrices until the size is 1x1). I.e., the recursion continues all ...

5 years ago | 1

Answered
How C++ gets struct values from Matlab
Looks like your strings are char type and not the newer string type. So you can try the following: mxArray *mx; char *name; ...

5 years ago | 0

Answered
Checking whether two complex matrices are equal
You can't rely on floating point calculations to give exact results. See this link: https://ch.mathworks.com/matlabcentral/ans...

5 years ago | 2

| accepted

Answered
IMU orientation using AHRS filter
I haven't used either of those functions, but from reading the doc maybe you need to use the conjugate of the quaternions in you...

5 years ago | 1

Answered
Quick way to Invert the matrix (A+D) where the inverse of matrix A is known and the matrix D is diagonal.
Are the values in D small compared to A^-1 ? Maybe you can make use of one of the forms listed here: https://en.wikipedia.org/...

5 years ago | 0

Answered
How do I program the orbit of a particle that is experiencing Gravity & Radiation Force Pressure?
The differential equation is simply Newton's F = ma, where m is the mass of the object (M1) and a is the acceleration of the obj...

5 years ago | 0

Answered
Numerical integration RK4 for the given data
E.g., a VERY SIMPLISTIC approach showing one step of Euler integration dt = some delta time value q = [1,0,0,0]; % Initial qua...

5 years ago | 0

| accepted

Answered
How to convert this 2D code segment with random number into the FORTRAN code?
For your particular case, looks like the MATLAB code could reduce to: Nx = 4; Ny = 4; c1 = 0.12; rr = 0.0001; D = c1 + rr*(...

5 years ago | 1

Answered
Matrix multiply result different from loops
MATLAB calls 3rd party BLAS library code to do matrix multiply. This is a highly optimized multi-threaded library. The orderin...

5 years ago | 1

| accepted

Answered
Why does defining a system of ODEs a different, but similar way yield very different solutions?
Do you simply need to apply that factor in the 6th spot? (kred(t)*CNiIIIH - kox(t)*CNiIIH - k2*CNiIIH*CH)*(96485.33289/1e9);

5 years ago | 0

Answered
atan2(0,0) is not undefined (NaN)
This is a documented convention. https://ch.mathworks.com/help/matlab/ref/atan2.html

5 years ago | 0

Answered
How to use not equal in for loop
You could use a while loop. E.g., t = 0; while( t ~= 1 ) % code % at some point, either set t=1 or break out of loop...

5 years ago | 0

Answered
Given that A is a sparse matrix, norm(A(i,:)) takes a very long time. Why and can one do better ?
Will you eventually need all of the rows? E.g., do this once at the beginning outside the loop n = sqrt(sum(A.^2,2)) And then...

5 years ago | 0

Answered
8bit binary sub string to unsigned integer in matlab
doc bin2dec

5 years ago | 0

Answered
Indexing in fields of a struct
Loops are what is needed here, but you can hide the loops behind function calls if you want. E.g., k = 3; % the number you are...

5 years ago | 0

| accepted

Answered
Using FP16 data in MATLAB
If you have R2018b or later, you can fread as uint16 and then typecast into half type. E.g., % Generate some sample data >> d...

5 years ago | 1

| accepted

Answered
I'm new to matlab and am trying to sort an array in ascending order without using the sort command. How would I rectify this?
This is a "bubble sort" and you have two problems. First, as mentioned by Walter, is your indexing max value is one too big. Y...

5 years ago | 1

Answered
Preallocating a sparse matrix, then entering values column by column takes too much time. Is there a more efficient way ?
The problem is that every time you change the elements of Q, even if it is only one element change, MATLAB generally has to copy...

5 years ago | 0

Answered
How to optimize matrix multiplication speed?
This looks like a covariance matrix update to me. The matrix multiplies are already done by highly optimized multi-threaded com...

5 years ago | 0

Answered
How to limit calculation precision?
You can get about that precision (a little less) by using the half data type: https://www.mathworks.com/help/fixedpoint/ref/hal...

5 years ago | 1

Answered
FOR LOOP NOT WORKING
Index your answers. E.g., if EXANGLES(i) < 90 EVANGLE1(i) = EVSUB1-FT126; elseif EXANGLES(i) == 90 ...

5 years ago | 0

Answered
Numerical Solution of the System of four Coupled Nonlinear ODEs by Runge-Kutta Fourth Order Method
I will point out some problems, and then suggest a much easier way to do this. Start with your first couple of lines in the loo...

5 years ago | 0

Load more