Answered
How to rearrange columns in a MATRIX?
One way: [X(:,1:2);X(:,3:4)]

3 years ago | 0

Answered
How to calculate the mean value of the non vero value in a vector?
Another way that doesn't require any data copying: M = [0.7,0.3,0]; sum(M)/nnz(M) Be aware that if there are no non-zero elem...

3 years ago | 1

Answered
Adding value from structure into a vector after each iteration of a for loop.
The reason you are getting a 2x8x2 answer is because you start with a 1x8 vector but then assign spots outside of those limits i...

3 years ago | 0

Answered
parallel sum different from serial sum
Bruno and IA have already given the reasons for this discrepancy. I would simply add that even though you are adding integers an...

3 years ago | 2

Answered
how to multiply quaternion wth 1x3 vector
Use BECI as the "vector" part of a quaternion and put a 0 in the "scalar" part, and use that new quaternion in the multiply. Sin...

3 years ago | 1

| accepted

Answered
I want to convert vector into matrix with all possible combinations
I think John D'Errico answered this some time ago, or a question very much like this. But I can't find his post at the moment. I...

3 years ago | 0

Answered
Can compare between vector and array
Does this do what you want? Finds the row numbers in A that match x. find(all(A==x,2))

3 years ago | 0

| accepted

Answered
Modify off diagonal elements of Matrix without looping
You could use logical indexing to get at the off-diagonal elements. E.g., A(~eye(size(A))) = skalar;

3 years ago | 0

| accepted

Answered
How to get two 16-bit numbers from a 32bit number
E.g., to split a uint32 into two uint16 you can use typecast( ): result = typecast(your_variable,'uint16') This result will co...

3 years ago | 0

Answered
pass a vector from matlab to a c++ program
This really depends on what your C++ program does, but the simplest approach is to use a mex routine. You will need a supported ...

3 years ago | 0

| accepted

Answered
Write multiple variables from a function
Maybe something like this does what you want, with each qq1 and qq2 2D page results in the first two dimensions. [m n] = size(s...

3 years ago | 0

Answered
In an assignment A(I) = B, the number of elements in B and I must be the same.
" And in the work space y2 is 3x1 and d is 1x1 " Then d - y2 will be 3x1. You can't assign a 3-element vector to a 1x1 scalar w...

3 years ago | 0

Answered
After the if statement is ran why is the answer 10?
A=1; : if A<0 A is not negative, so the body of the if-test never runs.

3 years ago | 0

Answered
Solve nonlinear 2nd order ODE numerically
You can look at the examples for ode45( ) here: https://www.mathworks.com/help/matlab/ref/ode45.html?searchHighlight=ode45&s_ti...

3 years ago | 1

Answered
The input function does not work well
Pass in a vector using the square brackets. E.g., binary_to_decimal([1 0 0 1 1 0])

3 years ago | 0

| accepted

Answered
Concatenate logical/numerical arrays element wise
Here is one way: % Generate sample data H{1} = rand(2,3)<0.5; H{2} = rand(2,3)<0.5; H{3} = rand(2,3)<0.5; Hc = cat(3,H{:}) ...

3 years ago | 2

| accepted

Answered
What is the difference between " while 1" and "while true", Should I use one over the other?
1 is a double class scalar and true is a logical class scalar, so the check for "non-zero" is slightly different for each even t...

3 years ago | 0

| accepted

Answered
I have a 4 Dimensional Matrix and i want to get its transpose
Maybe this does what you want, which is transpose the first two dimensions: permute(val,[2 1 3 4]) Or you could use this funct...

3 years ago | 0

Answered
How to multiply a 3d array with a 2d matrix?
It would be best if your 2D pages were the first two dimensions. That way the 2D pages are contiguous in memory and you can use ...

3 years ago | 1

Answered
Error in concatination in binary values
c1=[8 14 10 9 6 3 2 7 6 11 6 3 13 15 6 0]; NewR = c1(1:2:end)*16 + c1(2:2:end)

3 years ago | 0

Answered
Increased time for setting elements in sparse matrix
Every time you change the elements of a sparse matrix, MATLAB has to deep copy all the existing elements to a newly allocated ch...

3 years ago | 1

Answered
How to run a Matlab file which uses functions from .c and .dll files?
It appears that this may be an older mex routine? Is there a "mexFunction" in the c file? If so, maybe you can just recompile it...

3 years ago | 1

| accepted

Answered
Unable to perform assignment because the left and right sides have a different number of elements.
Why are you replacing the sin(y-c) term with approximations? Why haven't you just programmed it as is? It appears you have done ...

3 years ago | 0

Answered
Applying runge kutta for coupled equations
What are and ? Why don't they have differential equations associated with them? Can you give more details about this? Also, it...

3 years ago | 0

| accepted

Answered
How to create a loop on function handle
Isn't this just a standard matrix*vector multiply? E.g., XI = @(xi) xi - (y(i,:) + A*((t(i)+c*dt).*xi)*dt); Note that this fun...

3 years ago | 1

| accepted

Answered
Index Matrix A and Matrix B Problems
You can use logical indexing: B(A==1) = 0; You can use a loop for this also, but you would have to show us the code you used b...

3 years ago | 1

Answered
Whole derivation of two variable differential function
Please show the code you are using. y' means derivative of y with respect to x, not derivative of y with respect to y. You sho...

3 years ago | 0

Answered
How do i compile multiple fortran code from matlab command
To pass variables from MATLAB to your Fortran code you would typically do the following: Write a single gateway routine in a se...

3 years ago | 0

Answered
Updating Sparse Matrices every Time-Step Efficiently
To specify the sparse matrix size when creating it, use the following syntax: sparse(I,J,K,m,n) where m is the number of rows ...

3 years ago | 0

Answered
how to move a row
result = M([1:400,801,401:800,802])

3 years ago | 1

| accepted

Load more