Answered
Fastest multiple binary search in the same sorted large vector
Use FEX file here v=sort(rand(1e6,1)); u=rand(1e6,1); % Make sure v covers u on the right side v(end)=max(v(end),max(u)); ...

5 years ago | 0

Answered
Fastest multiple binary search in the same sorted large vector
v=sort(rand(1e6,1)); u=rand(1e6,1); ntests = 10; t=zeros(1,ntests); for k=1:ntests tic; [~,~,loc]=histcounts(u,v...

5 years ago | 1

Answered
Given One Partition of a Matrix, What is the Best Way to Find a Second Partition that Ensures the Matrix is Nonsingular?
C = [1 2 3 4 5;5 6 7 8 9]; [m,n] = size(C); [Q,R] = qr(C.'); p=n-m; X = rand(n,p); % X(m+1:n+1:end) = X(m+1:n+1:end) + 0....

5 years ago | 1

Answered
Find maximum array values avoiding mat2cell.
This is a method for multiple maxima by block. I post this for illustration of algorithmic mainly, because the real performance...

5 years ago | 1

Answered
call function for each combination of rows in A and columns in B
Simple for-loop is 3-4 times faster than fancy MATLAB pseudo vectorization, and much more readable Xtrain = rand(1000,2); Xtes...

5 years ago | 1

Answered
simple Matrix manipulation without for-loop needed
L(vec,:) = 0; L(sub2ind(size(L),vec,vec)) = 1;

5 years ago | 1

| accepted

Answered
How to find a minimum value of a matrix according to another matrix?
A=[1 1 2 3 3 2 4 5 4 5]; B=[0 3 10 6 15 22 23 28 21 25]; [AU,~,AA]=unique(A(:)); MB=accumarray(AA,B(:),[],@min); [AU,MB]

5 years ago | 0

| accepted

Answered
How to get next higher value from vector in Matlab ?
B = [0 0 1 2 4 -7 20 -9 -1 0]; d=diff([-Inf B -Inf],1); ip=find(d(1:end-1)>=0 & d(2:end)<=0); for idx=1:length(B) hi...

5 years ago | 1

Answered
How to fit a series of datapoints using 3 piecewise linear fit lines
Use this FEX load data.mat % attached above ydata(end) = []; % your xdata/ydata do not match in length ! slope0 = struct('...

5 years ago | 0

| accepted

Answered
bsxfun - @minus - how to divide by maximum
Do do poor job to explain, up to everyone guess >> a = [3; 5; 1;] a = 3 5 1 >> b = [3; 2; 3; 4] b ...

5 years ago | 0

| accepted

Answered
How to find coefficients of a polynomial , Given values of the function
t = [1; 2; 3; 4; 5]; y = [2.3; 4.8; 8.9; 16.9; 41.0] M=[ones(5,1), t, t.^2, -y.*t, -y.*t.^2]; x=M\y; c0=x(1); c1=x(2); c2=...

5 years ago | 1

| accepted

Answered
How can I replace the values from a diagonal submatrix?
>> A=rand(6) A = 0.8143 0.6160 0.9172 0.0759 0.5688 0.3112 0.2435 0.4733 0.2858 0.0540 ...

5 years ago | 2

Answered
How can I replace the values from a diagonal submatrix?
>> A=rand(6) A = 0.8147 0.2785 0.9572 0.7922 0.6787 0.7060 0.9058 0.5469 0.4854 0.9595 ...

5 years ago | 2

| accepted

Answered
Find maximum array values avoiding mat2cell.
Just a for-loop (is it allowed in Simulink?) A=[NaN, NaN, NaN, NaN, 1, 6, 8, 32, -5, NaN,NaN,NaN,NaN,NaN,NaN, 65, 2 ,16 80, 80,...

5 years ago | 2

| accepted

Answered
FIR filter has output of same length as its input?
There is the the difference equation in the "Rational Transfer Function" part of the doc. x(i) with i<=0 are supposed to be 0. ...

5 years ago | 0

| accepted

Answered
XOR on rising edge of two arrays
a = [0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,1]; b = [0,0,0,1,1,1,1,0,0,1,1,1,1,0,1,1,1]; a0 = [0; a(:)]; b0 = [0; b(:)]; i = find...

5 years ago | 1

| accepted

Answered
Best fit of ellipse equation to given data
There is one implementation I posted here https://www.mathworks.com/matlabcentral/answers/471640-how-to-fit-ellipse-equation-th...

5 years ago | 2

| accepted

Answered
Linear Regression with the Curve Fitting Toolbox for multiple instances of the same measurement
Group all your 5 cycles of data as a long vectors of xData + yData. Then call fitting once on those long vectors

5 years ago | 1

Answered
With mxMalloc() and mxSetDoubles(), mex function crash matlab
You seem to call mxGetM(prhs[0]) To get dimensions of the first parameter of calling c=my_expm(2,[1,0;0,2]') which is 2 and ...

5 years ago | 2

Answered
With mxMalloc() and mxSetDoubles(), mex function crash matlab
You must not call mxFree(tmpResult); Since the data is attached to the output.

5 years ago | 2

Answered
axis equal - a bug in the function?
It is. The unit length is the same, not the total length of the axis. If you want to enforce the limits use xlim/ylim commands ...

5 years ago | 0

Answered
Mex, how to make visual studio support C11 standard?
https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ "What’s not: While there is currently n...

5 years ago | 1

| accepted

Answered
optimization with interdependent variables?
Optimize with respect to z. Anything that depend on z, including y and x, such as objectve, constraints, upper bounds..., can b...

5 years ago | 0

| accepted

Answered
What is the Fastest manner to match rows of 2 matrices?
Save about half of the time nx = 3000; ny = 3000; m = 6000; x = rand(m, nx); y = rand(m, ny); y(:, randperm(ny, ny / 10...

5 years ago | 1

Answered
How to reduce the computation time for adding 3D-array?
You can reformulate the loop as convolution of A = accumarray([x(:) y(:) z(:)]-length(Small)/2,1,[500 500 500]) and B = flip(...

5 years ago | 1

| accepted

Answered
How to generate random points on a plane specified with a point and a normal vector?
N = [1; 2; 3]; % the normal to the plane xyz0=[4; 5; 6]; % point inside the plane sz = 4; % size of the rectangle n = 500; % ...

5 years ago | 2

| accepted

Answered
Inequality constraints for optimizer
% Your points that define the domain xg = randn(10,1); yg = randn(10,1); % The domain is concerted to the set defined by in...

5 years ago | 0

Answered
Is MPI Library available for MATLAB like it is available for C or Fortran?
No OpenMP is available for C and Fortran, using pragma/directive for compiled programing language on fix-variable type, with rig...

5 years ago | 1

Answered
Draw a letter on a sphere with puma560
x(t), y(t), z(t) are coordinates of the letter in 3D (tangent plane), then this vectors is on the sphere of radius 1 (x(t), y(t...

5 years ago | 0

Answered
Inverse of a function gives different results than the negative function with fmincon
If you apply a non-llinear transformation of your decision variables, I would expect the solver behave differently. The solver ...

5 years ago | 0

Load more