Answered
MATLAB: failed creating a diagonal matrix
You probably have inadvertently created a variable named 'diag' in your workspace, and hence diag(x) is simply indexing into thi...

4 years ago | 0

Answered
For-loops are now faster than some of the simplest vectorized statements. Why do we still need so much deep copying?
I have read rumors in the past that TMW was tinkering with the idea of sub-array references, or some type of limited pointer cap...

4 years ago | 1

| accepted

Answered
what correction is required in the code?
If the homework assignment specifies you must use a loop, then I don't think the intent was for you to wrap a simple i=1 range a...

4 years ago | 0

Answered
I am trying to solve 3rd order ode by RK45, but I did not get solution and plot, kindly fix my issues
The image appears to show seven equations (H1', H2', ..., H7') with boundary conditions at 0 and infinity. The RK45 scheme you ...

4 years ago | 0

| accepted

Answered
If statement in loop with AND OR operands
The problem is that the comparison Outcome{j} == '11_right' is an array comparison, not a scalar comparison. I.e., the string i...

4 years ago | 0

| accepted

Answered
How to create a equally distributed batting order for little league baseball team
Start with a simple pattern that works, and then randperm both the rows and columns. E.g., B = zeros(10); for k=1:10 % start w...

4 years ago | 0

| accepted

Answered
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2
Does this do what you want: Xindex(r, :) = [index rowidx]; You can get rid of c altogether since it isn't needed. And you nee...

4 years ago | 1

| accepted

Answered
How do I store a string from a MATLAB structure into a C structure in a MEX file?
Please show us the definitions of the variables involved. How large is cstructu->Field1, cstructu->Field2, and cstructu->Field3?...

4 years ago | 0

| accepted

Answered
How to calculate sum(A .* (B * C), 'all') [Ed. actually sum(A .* log(B * C), 'all')] efficiently when A is sparse and B*C is full and large?
Here is the straightforward mex code (i.e., no parallel sections) if you want to try it out. It computes the result directly in...

4 years ago | 3

| accepted

Answered
what does the expression " if ( ) && ( ) " do
&& is the "logical and" operator. You can read about it here: https://www.mathworks.com/help/matlab/ref/logicaloperatorsshortc...

4 years ago | 0

| accepted

Answered
How to calculate sum(A .* (B * C), 'all') [Ed. actually sum(A .* log(B * C), 'all')] efficiently when A is sparse and B*C is full and large?
You could use this loop to avoid the memory usage, but it will run slowly because of the data copying going on in the background...

4 years ago | 0

Answered
ODE system with 2 degrees of freedom
I only see two variables, 1 and 2, and each is part of a 2nd order equation. So that would mean a 2 x 2 = 4 element state vecto...

4 years ago | 0

| accepted

Answered
Extracting the sub-matrix
You might benefit from going through the onramp tutorials found here: https://matlabacademy.mathworks.com/details/matlab-onramp...

4 years ago | 1

Answered
How can I solve these differential equations?
A general outline would be to create your derivative function as follows: function dy = myderivative(t,y,T,E) Fa = y(1); Fb =...

4 years ago | 0

Answered
Exponent mantissa form of real numbers
Without seeing the actual wording of the assignment, I would assume this simply means "floating point notation". E.g., 123.456...

4 years ago | 1

Answered
Matrix product using for/while loop
The inner most loop needs to iterate over the 2nd index of M1, not the first index. E.g., while (k<=size(M1,2)) %<-- 2nd inde...

4 years ago | 0

| accepted

Answered
What does 'li' mean?
1i is used to ensure it isn't confused with a variable named i that you might have in the workspace. I.e., 1i is always sqrt(-1...

4 years ago | 0

Answered
I have matrix A and I need to find (e^(At)) where t is the sampling time. How to find that? Also what is the difference between exp(A) and expm(A)?
exp(A) just takes the exp( ) of the scalar elements individually. I.e., exp(A(1,1)), exp(A(1,2)), etc. expm(A) takes the matri...

4 years ago | 1

| accepted

Answered
help with my 4th order runge kutta code
My guess without seeing the rest of your code is that phi is a column vector, so when you add phi*h to the row vector Y(i,:) it ...

4 years ago | 0

| accepted

Answered
how to change from for loop to while loop
You never change i or Errors within the while loop, so how is the loop ever supposed to exit? Maybe you want to add this line: ...

4 years ago | 0

Answered
Is mxCopyPtrToInteger4() not compatible with Interleaved Complex API ?
See this post: https://www.mathworks.com/matlabcentral/answers/93860-why-does-the-fortran-mex-api-function-mxcopyptrtointeger4-...

4 years ago | 0

| accepted

Answered
What should go in a next-generation MATLAB X?
Symmetric variables and Hermitian variables. MATLAB could implement bit flags in the mxArray header to indicate this and they c...

4 years ago | 0

Answered
Why indexing vs not indexing the 2D matrix will lead to different result?
Some links related to this known behavior: https://www.mathworks.com/matlabcentral/answers/599818-computational-complexity-of-m...

4 years ago | 0

Answered
Properly resizing mxCreateStructMatrix post-2018a?
TMW doesn't publish the complete rules for how the data areas of structs are organized, but historically they have always put ea...

4 years ago | 0

Answered
How to get the ceofficients of a expression derived by ODE or integral ? For exampli,C1 and C2 in u
Typically these would be obtained by combining the solution with initial values for u. Do you have initial values?

4 years ago | 0

Answered
Conversion Wolfram Mathematica to Matlab (Do loop)
result = sum(1:100);

4 years ago | 0

Answered
Is it possible to vectorize this 'for loop' involving multiple matrix inversions
You might look at this FEX submission by Bruno Luong: https://www.mathworks.com/matlabcentral/fileexchange/24260-multiple-same-...

4 years ago | 0

| accepted

Answered
Mulitplying 3D matrix by 3D matrix - result being 4D.
result = pagemtimes(matrix1,reshape(matrix2,3,512,1,512));

4 years ago | 0

| accepted

Answered
Matrix dimensions must agree error problem
Use element-wise division with the dot: Y=acosd(sin(altitude)*sin(latitude)-sin(declination)./(cos(altitude)*cos(latitude))); ...

4 years ago | 0

Answered
Combining two Matrices every other row
You could do direct assignment. E.g., [m,n] = size(A); C = zeros(2*m,n); C(1:2:end,:) = A; C(2:2:end,:) = B;

4 years ago | 1

Load more