Answered
What motivates you to contribute on Matlab Answers?
I find it a good way to see what other people are working on, and what's prominent in STEM fields in general. I also find it a ...

4 years ago | 1

Answered
How to draw irregular curve using random data ?
t=pi/180*(0:10:360); r=5+0.5*(rand(size(t))*2-1); r(end)=r(1); tq=linspace(t(1),t(end),1000); rq=spline(t,[0,r,0],tq); ...

4 years ago | 0

| accepted

Answered
GA is suddenly much slower (no other visible effects)
As a troubleshooting strategy, I suggest putting a tic...toc as the first and last lines of the fitness function. This way you c...

4 years ago | 0

| accepted

Answered
Exclude rows from table if multiple conditions are met
A=randi(5,5); A(A<=4)=nan A(all(isnan(A),2),:)=[]

4 years ago | 0

Answered
Finding common elements in an array (even if they are not in the same position)
a=1:10 b=[1,11] c=intersect(a,b)

4 years ago | 0

| accepted

Answered
How to improve this function execution?
Since the code provides many calls of this function Instead of calling the function multiple times, call it just one time or ju...

4 years ago | 0

Answered
How do you rotate an ellispoid?
Use rotate.

4 years ago | 1

Answered
Reduce memory use when doing element-wise multiplication of repeated (repmat/repelem) matrices? (Final product is more sparse than intermediate computations.)
or , where F is ones(1,s3), D is ones(s1,s2), and E is ones(s4), This solution eliminates the need to form the Kronecker produc...

4 years ago | 0

Answered
extract control points of curve with spline
But, nobody wants to extract minimum number of control points out of a given curve!!! There is no minimum number unless the gi...

4 years ago | 0

Answered
How to perform linear curve fitting based on distance from line instead of residuals
You can use linear2dFit() from this FEX package, https://www.mathworks.com/matlabcentral/fileexchange/87584-object-oriented-too...

4 years ago | 0

Answered
Comparing indices in columns of a matrix
matrix=randi(5,5,10); %Example input [m,n]=size(matrix); LUT=1:n; out=cell(m,1); for i=1:m G=findgroups(matrix...

4 years ago | 0

| accepted

Answered
Using static classes over packages
I don't think static classes have any pitfalls, but I'm not sure I agree that it is "cleaner". Why is having 10 functions in a f...

4 years ago | 1

| accepted

Answered
Fitting a straight line to scattered portion of data and then extrapolation straight line to intersect x axis
You don't need to drag the line to find the x-intercept. Just use roots, p=polyfit(x,y,1); xIntercept=roots(p); or even jus...

4 years ago | 0

| accepted

Answered
Mean of matrix elements that have same value in the first column
dmRe_40=varfun(@mean,array2table(dmRe_40),'Grouping',1); dmRe_40=table2array(dmRe_40(:,[1,3:end]));

4 years ago | 0

| accepted

Answered
Mean of matrix elements that have same value in the first column
[G, ID]=findgroups( dmRe_40(:,1) ); dmRe_40=[ID, splitapply(@(z) mean(z,1) , dmRe_40(:,2:7), G)];

4 years ago | 0

Answered
Limiting the sensitivity of initial guess in NLS Optimization/lsqnonlin/fmincon
For every fixed choice of c4,c5,c6 your optimization problem reduces to a linearly constrained least squares sub-problem, solvab...

4 years ago | 0

| accepted

Answered
How to define if a point is inside or outside a 3D pyramidal area?
Download this FEX submission, https://www.mathworks.com/matlabcentral/fileexchange/30892-analyze-n-dimensional-convex-polyhedra...

4 years ago | 1

Answered
How to define if a point is inside or outside a 3D pyramidal area?
Just camera project the point(s) onto the plane of A,B,C,D and use inpolygon to see if it lies between them. If the plane of AB...

4 years ago | 1

Answered
Mean value of a certain number range
vector=rand(1,100)*4+22.01; subset=vector>22.93 & vector<24.76; mean(vector(subset))

4 years ago | 0

| accepted

Answered
Best tool to calculate the parameters of a custom equation fit
For your particular equation, I'd rcommend, [a,b,c]=deal(3,2,1) x=linspace(1,2,30); %fake data y=a+b./x.^2.*exp(-x/c); ...

4 years ago | 1

| accepted

Answered
create a sparse multidimensional matrix
n=3; A=kron(speye(n),[0;0;1;0]) full(A)

4 years ago | 0

Answered
To find intersection point of two lines ?
How do you solve a special case when the slope is 0, Inf or –Inf? Use linexlines2D (Download) which doesn't make any assumption...

4 years ago | 0

Answered
How to add user defined function as constraint for optimization?
Ultimately, you must use the solver-based approach, like Torsten says. However, if you download this, https://www.mathworks.com...

4 years ago | 0

| accepted

Answered
Finding number(s) that is(are) repeated consecutively most often
Using, https://www.mathworks.com/matlabcentral/fileexchange/78008-tools-for-processing-consecutive-repetitions-in-vectors >> ...

4 years ago | 0

Answered
Finding Coefficients to Construct a Vector Using Defined Basis
Make the basis vectors the columns of a matrix A and then use mldivide, coefficients=A\b Here b is the column vector you are t...

4 years ago | 1

| accepted

Answered
How to avoid using det, when looking for the complex root w with det(M(w)) = 0
Because your matrix appears to be symmetric, I suggest minimizing instead norm(M(w)) which is the maximum absolute eigenvalue of...

4 years ago | 0

Answered
Optimisation functions: Skipping iterations if objective function returns an error or cannot run completely
Basically, the option available to you is to return inf from your objective when an error condition is reached. Some optimizatio...

4 years ago | 1

| accepted

Answered
fill a vector (efficiently) with values specified by matrix and multiple vectors
M=reshape(1:8,2,2,2);N=10; x=(rand(N,1)>0.5)+1;y=(rand(N,1)>0.1)+1;z=(rand(N,1)>0.1)+1; OUT=M( sub2ind(size(M),x,y,z) ...

4 years ago | 1

| accepted

Answered
Interpolating points in a 3D space with one line
You can use linear3dFit() from this FEX submission https://www.mathworks.com/matlabcentral/fileexchange/87584-object-oriented-t...

4 years ago | 1

Load more