Answered

find the position of all non-zero minimum values in each column of a matrix

a = [2 0 3;1 2 5;0 0 0;1 3 3;0 0 6;0 2 7;1 0 0] b=a; b(b==0)=NaN; [r,c]=find(b==min(b,[],1)); rmin=accumarray(c(:),r(:),[siz...

find the position of all non-zero minimum values in each column of a matrix

a = [2 0 3;1 2 5;0 0 0;1 3 3;0 0 6;0 2 7;1 0 0] b=a; b(b==0)=NaN; [r,c]=find(b==min(b,[],1)); rmin=accumarray(c(:),r(:),[siz...

en dag ago | 1

Answered

Turn logical matrix into string vector

Assuming idx has one 1 per row idx = logical([0 1 0; 0 0 1; 1 0 0; 1 0 0; 0 1 0]); vec = ["A","B","C"]; [r,c]=find(idx); r...

Turn logical matrix into string vector

Assuming idx has one 1 per row idx = logical([0 1 0; 0 0 1; 1 0 0; 1 0 0; 0 1 0]); vec = ["A","B","C"]; [r,c]=find(idx); r...

6 dagar ago | 0

Answered

Symetric matrix power optimization

Youeu can edit MATLAB function mpower.m and try to the basic calculation (line 76 in my case) D = D*D; % I assume p is integer...

Symetric matrix power optimization

Youeu can edit MATLAB function mpower.m and try to the basic calculation (line 76 in my case) D = D*D; % I assume p is integer...

7 dagar ago | 0

| accepted

Answered

How can I avoid loop for code optimization?

Use MultipleQR FEX (C compiler for MEX build is required, unless for Windows platform) y = linspace(1,10,1000); Y = reshape(...

How can I avoid loop for code optimization?

Use MultipleQR FEX (C compiler for MEX build is required, unless for Windows platform) y = linspace(1,10,1000); Y = reshape(...

8 dagar ago | 1

Answered

random number of two random varibles.

If K is the (2 x 2) covariariance matrix of (w,T) and mu (2 x 1) is the mean of (w,T), you can generate them like this n = 100...

random number of two random varibles.

If K is the (2 x 2) covariariance matrix of (w,T) and mu (2 x 1) is the mean of (w,T), you can generate them like this n = 100...

8 dagar ago | 0

Answered

How to avoid a negative solution with fmincon, including an external equation?

The condition f2 = - 2*x1 - 10*x2 + 30 >= 0 is equivalen to 2*x1 + 10*x2 + 0*f1 <= 30. So set A = [2 10 0] b = 30 If you ...

How to avoid a negative solution with fmincon, including an external equation?

The condition f2 = - 2*x1 - 10*x2 + 30 >= 0 is equivalen to 2*x1 + 10*x2 + 0*f1 <= 30. So set A = [2 10 0] b = 30 If you ...

9 dagar ago | 0

| accepted

Answered

How can I optimize coefficients of a polynomial using fmincon?

"The overall goal is to minimize the length of the cost function " The overall length is L = integral sqrt(dx/dt^2+dy/dt^2+dy/...

How can I optimize coefficients of a polynomial using fmincon?

"The overall goal is to minimize the length of the cost function " The overall length is L = integral sqrt(dx/dt^2+dy/dt^2+dy/...

9 dagar ago | 0

Answered

Is it possible to vectorize this?

NOTE the order of most is sorted with this algorithm: A = [1 2 0 3 4 6; 9 3 4 0 9 5; 4 3 0 5 6 7; 3 7 7 3 0 0...

Is it possible to vectorize this?

NOTE the order of most is sorted with this algorithm: A = [1 2 0 3 4 6; 9 3 4 0 9 5; 4 3 0 5 6 7; 3 7 7 3 0 0...

9 dagar ago | 2

Answered

Diagonal of non-square matrix

n = 8; A = spdiags([2 3 4]+zeros(n,1),0:2,n,n+2); A = full(A) % if prefered

Diagonal of non-square matrix

n = 8; A = spdiags([2 3 4]+zeros(n,1),0:2,n,n+2); A = full(A) % if prefered

9 dagar ago | 1

Answered

Randomly splitting of a number in a sum format.

This code will generate "uniform" partition distribution, in the sense that all possible partition has equal probability: n = 1...

Randomly splitting of a number in a sum format.

This code will generate "uniform" partition distribution, in the sense that all possible partition has equal probability: n = 1...

9 dagar ago | 1

Answered

Will codegen accelerate sub-functions?

Yes coder translates the sub-functions to C as well.

Will codegen accelerate sub-functions?

Yes coder translates the sub-functions to C as well.

9 dagar ago | 0

| accepted

Answered

Randomly splitting of a number in a sum format.

n = 10; for j=1:10 r = n; i = 1; clear s while r > 0 s(i) = ceil(r*rand); r = r-s(i); ...

Randomly splitting of a number in a sum format.

n = 10; for j=1:10 r = n; i = 1; clear s while r > 0 s(i) = ceil(r*rand); r = r-s(i); ...

9 dagar ago | 0

| accepted

Answered

mldivide algorithm for an underdetermined system of equations

The outline of "\" goes as following: % Test data A=randi(10,3,2)*randi(10,2,5) b=randi(10,3,1) [Q, R, P] = qr(A,'vector')...

mldivide algorithm for an underdetermined system of equations

The outline of "\" goes as following: % Test data A=randi(10,3,2)*randi(10,2,5) b=randi(10,3,1) [Q, R, P] = qr(A,'vector')...

10 dagar ago | 1

| accepted

Answered

Function to create struct with parameters

s = buildparams() function s = buildparams() a = 1; b = 2; s = gathervars(); end function s = gathervars() vars = eva...

Function to create struct with parameters

s = buildparams() function s = buildparams() a = 1; b = 2; s = gathervars(); end function s = gathervars() vars = eva...

10 dagar ago | 0

Submitted

nchoosek_enum

nchoosek with enumerate selection. This function never build the full combination array in memory

10 dagar ago | 2 downloads |

Answered

Creating separate combinations with repetition

I program a function nchoosek_enum that is almost like nchoosek, excepted that you can pass an enumerated array i that selects t...

Creating separate combinations with repetition

I program a function nchoosek_enum that is almost like nchoosek, excepted that you can pass an enumerated array i that selects t...

11 dagar ago | 0

Answered

How to get all combinations from this matrix?

ch=['MRWI' 'IDMZ' 'CGBI' 'JKNO']; c=num2cell(ch,2); [c{:}]=ndgrid(c{:}); n=size(c,1); c = reshape(cat(n+1,c{:}),[],n)

How to get all combinations from this matrix?

ch=['MRWI' 'IDMZ' 'CGBI' 'JKNO']; c=num2cell(ch,2); [c{:}]=ndgrid(c{:}); n=size(c,1); c = reshape(cat(n+1,c{:}),[],n)

12 dagar ago | 0

| accepted

Answered

How to trim the non-manifold triangle off the stl file?

There is SW that can detect topology issue and attempt to correct it, such as https://www.meshlab.net/

How to trim the non-manifold triangle off the stl file?

There is SW that can detect topology issue and attempt to correct it, such as https://www.meshlab.net/

14 dagar ago | 0

Answered

how to count the number of occurrences of these numbers (with some conditions)

A(1,:) = [1, 2, 5, 2 , 1 , 2]; A(2,:) = [0,1,1,0,1,0]; [B,~,J] = unique(A(1,:)); N = accumarray(J(:),A(2,:)'); B = B'; ta...

how to count the number of occurrences of these numbers (with some conditions)

A(1,:) = [1, 2, 5, 2 , 1 , 2]; A(2,:) = [0,1,1,0,1,0]; [B,~,J] = unique(A(1,:)); N = accumarray(J(:),A(2,:)'); B = B'; ta...

14 dagar ago | 0

| accepted

Answered

How to select complementary elements from a vector?

d = [33 20 4 5 6 75 8 9 0]; I = [1 3 7]; d(I) = []

How to select complementary elements from a vector?

d = [33 20 4 5 6 75 8 9 0]; I = [1 3 7]; d(I) = []

16 dagar ago | 0

Answered

How to select complementary elements from a vector?

d = [33 20 4 5 6 75 8 9 0]; I = [1 3 7]; d(setdiff(1:end,I))

How to select complementary elements from a vector?

d = [33 20 4 5 6 75 8 9 0]; I = [1 3 7]; d(setdiff(1:end,I))

16 dagar ago | 0

| accepted

Answered

Multiple griddata calls into a single one (same grid)

For nearest/linear/cubic method you can build the matrix https://www.mathworks.com/matlabcentral/fileexchange/85939-mat-op-ex, f...

Multiple griddata calls into a single one (same grid)

For nearest/linear/cubic method you can build the matrix https://www.mathworks.com/matlabcentral/fileexchange/85939-mat-op-ex, f...

20 dagar ago | 0

Answered

Multiple griddata calls into a single one (same grid)

If you are ready to trade 'v4' method for something else, you can use scatteredInterpolant % example of fake data x = -3 + 6...

Multiple griddata calls into a single one (same grid)

If you are ready to trade 'v4' method for something else, you can use scatteredInterpolant % example of fake data x = -3 + 6...

20 dagar ago | 0

Answered

Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

The for loop varable is lowercase L char "l" (l), not one "1" (1) for l=1:n

Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

The for loop varable is lowercase L char "l" (l), not one "1" (1) for l=1:n

20 dagar ago | 0

Answered

Passing structs/objects to functions

"Does the compiler realize which parts of the struct are actually needed and pass only these to the function? " MATLAB don't pa...

Passing structs/objects to functions

"Does the compiler realize which parts of the struct are actually needed and pass only these to the function? " MATLAB don't pa...

20 dagar ago | 0

| accepted

Answered

Smallest number of data type single

>> realmin('single') ans = single 1.1755e-38 >>

Smallest number of data type single

>> realmin('single') ans = single 1.1755e-38 >>

21 dagar ago | 0

Answered

Please help me vectorize my loop to construct query vector from sample points

xs=cumsum(ceil(10*rand(1,10))) t=pi; p=cumsum([0 ceil(diff(xs)/t)]); xq=interp1(p,xs,0:p(end))

Please help me vectorize my loop to construct query vector from sample points

xs=cumsum(ceil(10*rand(1,10))) t=pi; p=cumsum([0 ceil(diff(xs)/t)]); xq=interp1(p,xs,0:p(end))

23 dagar ago | 0

| accepted

Answered

Non-convex shape as a collisionBox for robot path planning

The MATLAB probably use GJK algorithm that requires convex shape. You should split the object in sum of convex. I can recommend...

Non-convex shape as a collisionBox for robot path planning

The MATLAB probably use GJK algorithm that requires convex shape. You should split the object in sum of convex. I can recommend...

23 dagar ago | 0