Answered
How to plot a function that has a parameter in the interval?
Using the Symbolic Math Toolbox (if you have it): syms t a=1; f=piecewise(0<t & t<a, exp(t), t>=a, 2*exp(t)); fplot(f,...

3 years ago | 0

| accepted

Answered
How to plot a function that has a parameter in the interval?
One possibility: a=1; f=@(t) exp(t).*(0<t & t<a) + 2*exp(t).*(a<=t); fplot(f,[0,2*a])

3 years ago | 0

Answered
how to solve two equation with 2 variables
You could use fsolve or fminsearch fun=@(x) [sin(x(2))+2*x(2); sin(x(1)-1)+2*(x(1)-1)]; [x,fval]=fsolve(fun,[0;0]) [x,f...

3 years ago | 0

| accepted

Answered
trust-region reflective algorithm in lsqnonlin and fmincon: same behavior for "unconstrained" optimization"?
No, they are not the same. They both take steps in a 2D subspace, but for fmincon, the basis vectors for the subspace are determ...

3 years ago | 1

| accepted

Answered
How can I find a cubic bezier curve that minimizes curvature with the Optimization framework?
It's not fminsearch's fault. The function you have created returns the same value all the time: P0 = [0, 0]; P3 = [10, 10]; %...

3 years ago | 1

| accepted

Answered
while loops and prime numbers
Can't you use isprime()? isprime(7) isprime(4)

3 years ago | 0

Answered
Is there a way to have LiveScript buttons call arbitrary functions?
This might be relevant: https://www.mathworks.com/help/matlab/creating_guis/create-simple-live-editor-task.html

3 years ago | 0

Answered
How to implement PyTorch's Linear layer in Matlab?
Another approach is to write your own custom layer for channel-wise matrix multiplication. I have attached a possible version of...

3 years ago | 0

Answered
How to implement PyTorch's Linear layer in Matlab?
Another possible way to interpret your question is that you are trying to apply pagemtimes to the input X with a non-learnable m...

3 years ago | 0

Answered
matlab plot bar problem
Are you asking how to stack the bars? If so, see this example: https://www.mathworks.com/help/matlab/ref/bar.html?searchHighlig...

3 years ago | 0

Answered
functions does not appear
You cannot create non-anonymous functions in the command window. You need to compose them in a .m file. It is recommendable that...

3 years ago | 0

Answered
Solve linear tensor equation
n=5; A=rand(n,n,2,2); utrue=rand(n,2); f=tensorprod(A,utrue,[2 4],[1 2]); A=permute(A,[1,3,2,4]); A=reshape(A,2*n,2*n); ...

3 years ago | 0

| accepted

Answered
How to implement PyTorch's Linear layer in Matlab?
One possibility might be to express the linear layer as a cascade of fullyConnectedLayer followed by a functionLayer. The funct...

3 years ago | 0

Answered
No feasible solution in optimisation in linprog
Your problem is infeasible because of the input problem data you provided, not because of coding errors. In particular, in Marke...

3 years ago | 0

| accepted

Answered
Interpolate Missing Pixels in an Image
You can use either fillmissing o regionfill. The fact that the pixel values are complex is not key. You can operate on the real ...

3 years ago | 1

| accepted

Answered
How can I change the resolution of my plots?
You can zoom in the portion of the contour plot where you want the contour labels better resolved, e.g., openfig untitled.fig

3 years ago | 0

| accepted

Answered
Inlined code segment slower than internal function pass - why?
with the inlined version merely as a result of not needing to pass the gargantuan array as an argument (and potential memory lim...

3 years ago | 0

Answered
Can't use function in summation
I would suggest not using syms, except when it is truly necessary. domain=1:150; uStep=(domain>=1); energy=cumsum(uStep./doma...

3 years ago | 0

Answered
Transformation matrix to rotate image
See the section Image Transformations with Localized Responses (localfunc2mat) under the Examples tab of this FEX download, ht...

3 years ago | 0

| accepted

Answered
Minimizing a prebuilt cost function
Just to sumarize, x0 should only be a single unkown output in this case. If so, both lsqnonlin and fmincon are overkill. You sh...

3 years ago | 0

Answered
Number of observations in X and Y disagree. - Error training a U-Net for classification
You have 100 training images. Therefore, B should be 100x1, not 6400x1.

3 years ago | 0

Answered
Ellipse from drawellipse is too small to drag
Interestingly, I find that Shift-LeftClick plus a very slight movement of the mouse puts the ellipse in translation mode, no mat...

3 years ago | 0

| accepted

Question


Ellipse from drawellipse is too small to drag
I have used drawellipse() to create an ellipse overlaid on an image. However, because the dimensions of the ellipse are small, I...

3 years ago | 1 answer | 0

1

answer

Answered
Use of fmincon to contain all data points with circle
Instead of fmincon, minboundcircle from this FEX download https://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of...

3 years ago | 0

Answered
fzero not able to find roots of a nonlinear eqation
Better to use contourc here, I would say: fun = @(x, y) vi.*y+lam*atan2(y,(x+b))./(2*pi)-lam.*atan2(y,(x-b))./(2*pi)-c; [X...

3 years ago | 0

Answered
dbstop if error: before it was stopping at error in my code, now set the break point into Matlab native functions
Since you're using R2022, you should be able to use the drop-down or tab bar in the Editor to go directly where you want in the ...

3 years ago | 0

Answered
Vectorized solution to replace for loops in nested combinations
Well, you can at least reduce it to 2 loops: T=50; nb2 = zeros( T, 1 ); tic for t = 1:T t1=0:t; ...

3 years ago | 0

| accepted

Answered
Optimization Curve Fitting: Curves are not converging
One immediate problem that I see is that in sseval, the optimization variables x(i) aren't used at all in the calculation of sse...

3 years ago | 0

Answered
What does this script mean?
It means minimize fun(x) over x for each set of fixed parameters t,c,p,VN. The initial guess for the minimization is g. The mini...

3 years ago | 0

Answered
How to use the Sum function in this instance
Assuming all your variables (x,z,Ar, etc...) are scalars, then, fi=5:85; q1=0.5*cosd(fi).^2; q2=q1+z^2; q3=sqrt(x^2+q2); ...

3 years ago | 0

Load more