Answered
Count the occurence certain elements based on condition in next column
U=unique(A(:)); [~,J]=ismember(A(B~=0),U); n=accumarray(J(:),1,size(U)); C=[U,n]

5 years ago | 0

| accepted

Answered
fminunc for upper and lower bound variable definition ?
You could transform variables, x will be opened bounded by lo/hi xfun = @(y) lo + (hi-lo).*sin(y).^2 ... y = fminunc(obj(xfu...

5 years ago | 1

Answered
Find repeating rows in a matrix and replace with zeros
M = [9 10; 9 10; 9 10; 9 10; 9 10; 7 12; 3 4; 3 4; 3 4; 3 4; 7 12]; minlgt = 3; % keep all rows consecutively repeated at least...

5 years ago | 0

Answered
How to create a circulant matrix column wise?
col = rand(16,1) % your 1-column vector A = toeplitz(col,col(mod((1:20)-1,end)+1))

5 years ago | 0

Answered
How to reshape array based on another array with nan values
a = [2 6 5 4 7 2 3 2 3 1] b = [1 1 1 0;1 1 1 1;1 0 1 1] A = nan(size(b')); A(b'==1) = a; A = A.'

5 years ago | 0

| accepted

Answered
how many significant figures matlab uses?
MATLAB does not work directly on digit. MATLAB uses IEEE 754 BINARY storage which is 52-bit (relative) precision. Which is >> ...

5 years ago | 0

| accepted

Answered
Faster Looping for Griding/Binning Data
test2 = histcounts2(test1(:,2),test1(:,3),lonedges,latedges)

5 years ago | 0

| accepted

Answered
Accumarray error: Second input val must be full numeric, logical, or char vector or scalar
Convert your table to regular array A = table2array(TestCase2 ) Then do the rest on A.

5 years ago | 0

Answered
Solving "transposed" Lyapunov equation AX+X'B=Q
Sove to real equation. It might take a couple of minutes for matrix of size 1024, but this code using iterative solver seems ab...

5 years ago | 0

Answered
Polynomial with function handle.
function fh = get_polynomial_handle(p) function fn = poly1(x) fn=poly(p); function polynomial = poly(p) ...

5 years ago | 0

Answered
Optimising Nearest Neighbor Program
I put my comments as answer here, so you can accept if it helps N=20000; nd=3; pos=rand(nd,N); pos_r = reshape(pos,[nd 1 N...

5 years ago | 1

| accepted

Answered
HELP ME PLEASE with this geometric mean
Assuming A is the vector of your data geomean = exp(mean(log(A)))

5 years ago | 0

Answered
Imposing positive semi-definiteness and symmetry in fmincon
Equivalently impose the smallest eigen value is >= 0 (using non-linear constraint). I guess you must already ensure the matrix...

5 years ago | 1

Answered
Are handle classes the fastest containers?
I did not run your code, just read through but I believe you run into the fact that MATLAB makes cdata opy when you change an el...

5 years ago | 0

| accepted

Answered
Optimising Nearest Neighbor Program
I remove your hanling of offset (not sure what is the purpose), and this is a much faster method using delaunay triangulation: ...

5 years ago | 0

Answered
How to find b spline values?
After computing the derivative spline_position = spaps(time ,x,0,3); % x is a 101 element vector representing postion, I'm...

5 years ago | 0

| accepted

Answered
How to efficiently match the zeros of 1 matrix with another
The 3 for-loops can be shrink down to S(D==0) = 0;

5 years ago | 1

Answered
Why isn't eig returning all eigenvectors?
When you have multiple-order eigen value(s), the number of eigen vectors is not necessary equal to the order. Much simpler exam...

5 years ago | 0

| accepted

Answered
mxn and nxn matrix element-wise multiplication without for loop
AA = permute(reshape(A,[n,k,n]),[2 1 3]); results = AA(:,:)*B(:)

5 years ago | 0

| accepted

Answered
Generate some points on the plane restricted by 3 points (triangle)
Another method: n = 1000; % number of random points p1 = [1 1 2]; p2 = [5 7 3]; p3 = [8 2 1]; w = -log(rand(3,n)); xyz =...

5 years ago | 1

Answered
MEX api and interleaved complex arrays
Where have you been Jan? In a cave? ;-) Sorry it couldn't resist. As I understand, when you call mxGetPr and mxGetPi, the data...

5 years ago | 1

| accepted

Answered
solve linear equation system with partially unknown coefficient matrix
Just using linear algebra, no extra tollbox is needed, of course n==1 is underdetermined problem % Generate random matrix n =...

5 years ago | 1

| accepted

Answered
MATLAB CODING - SIGNAL CONVOLUTION
x=[ 1 2 -2 4 6]; h=[ -1 2 3]; c=conv(x,h) M=convmtx(h,length(x)) x*M % return c

5 years ago | 0

| accepted

Answered
When the algorithm of Levenberg-Marquardt is preferred when doing curve fitting?
Trust region is more robust if you have strong non-linearity. This effect is "amplified" depends also how far the starting point...

5 years ago | 1

| accepted

Answered
Matlab Memory Consumption: moving surfaces?
I can copy/past my "answered" in this question: yes I have the same issue.

5 years ago | 0

Answered
How to plot sphere in sphere coordinates?
function sphere(r) phi = linspace(0,2*pi); theta = linspace(0,pi).'; % first change x = r*cos(phi).*sin(theta); y = r*sin(ph...

5 years ago | 1

Answered
Comparing all the elements of an array with all the elements of another array
This returns the elements in order as in B, from left to right A = 100:10:600 B = [100 103 105 120 123 128 130 200 205 207 300...

5 years ago | 1

| accepted

Answered
How to solve explicit equation of ellipse
There is a function EllAlg2Geo ready to use in this FEX % Random coefficients for test: A = 0.5+rand; D = 0.5+rand; B = rand...

5 years ago | 0

Load more