Question


Is there a way to specify objective and constraint gradients when doing nonlinear optimization in the problem-based framework?
In the solver-based framework, user-applied gradients are specified as additional output arguments from the objective and constr...

4 years ago | 1 answer | 0

1

answer

Answered
fmincon nonlinear inequality constraint
The nonlinear constraints are not obeyed at all iterations. At iterations where they are not obeyed, chol() will give you an err...

4 years ago | 2

| accepted

Answered
Remove centroid locations of objects that are too close
A=[xf(:) yf(:)]; D=pdist2(A,A); D(D==0)=inf; %retroactive EDIT keep = all(D>d,1); xf=xf(keep); yf=yf(keep);

4 years ago | 1

| accepted

Answered
Number of .mat files into single .mat file
It depends what they contain and how you want the variables joined within the final .mat file. One way: filenames="data"+(1:10...

4 years ago | 1

| accepted

Answered
Calibration) How can i get to know multiplying order of Rotation matrix corresponding each axis?
(1) There is no single, unique ordering of Rx,Ry,Rz when you decompose a rotation matrix. You have 6 different choices for the o...

4 years ago | 0

Answered
why is acumarray much slower calculating means than sum?
I suspect it is because, when you pass in @sum, accumarray is smart enough to recognize that it can use its default settings, wh...

4 years ago | 2

Answered
How to use lsqnonlin command for solving a cost function minimization problem which consists of optimization variable?
If you have an objective created with optimvar variables, you would solve the problem by using the solve command, C = [0 0 0 1 ...

4 years ago | 0

| accepted

Answered
limits of Optimization variable can be another variable in problem based optimization?
No, you must use a linear inequality constraint: PbattV1 = optimvar('PbattV1',N,'LowerBound',0); prob.Constraints.conName=(P...

4 years ago | 0

| accepted

Answered
How to convert an optimization variable to symbolic variable?
You can use the evaluate() command to substitute in values.

4 years ago | 0

Answered
Set elements in a 3D array to zero based on a condition
Qr=max(Qr,0);

4 years ago | 0

Answered
Set elements in a 3D array to zero based on a condition
Qr(Qr<0)=0;

4 years ago | 0

| accepted

Answered
reduction variables and evaluation order
First remember that each worker is assigned some consecutive subset of loop iterations. The worker will execute the iterations w...

4 years ago | 0

| accepted

Answered
max value of a function
In general I use: x= double(solve(diff(func))); This assumes there are no local min/max or saddle points. if i try to use max...

4 years ago | 1

| accepted

Answered
Fastest way to compute a multiplication of matrices times a sequence of kronecker products
With this FEX package https://www.mathworks.com/matlabcentral/fileexchange/25969-efficient-object-oriented-kronecker-product-ma...

4 years ago | 0

| accepted

Answered
for loop storing the same variable
Because in every pass through the loop, you assign the result to the same location. Perhaps you meant, demodulated_power_vector...

4 years ago | 0

| accepted

Answered
Error when using sptensor in parfor
You could try with ndSparse() instead of sptensor() https://www.mathworks.com/matlabcentral/fileexchange/29832-n-dimensional-sp...

4 years ago | 0

| accepted

Answered
Calculate the mean of nonzero pixels and setting a threshold
fun=@(z) nanmean(z(z<99)); my_mean = accumarray(double(mask(:))+1, my_array(:),[], fun)

4 years ago | 1

Answered
Can I use a nearest neighbor extrapolation strategy with interp1?
If you want to mix interpolation and extrapolation methods, use griddedInterpolant instead: F=griddedInterpolant(1:5,'linear','...

4 years ago | 0

| accepted

Answered
Find unique number sets
A = [1 4; 2 3; 3 2; 1 4]; [B,iA]=unique(sort(A,2),'rows')

4 years ago | 0

| accepted

Answered
How to find all possible 8x8 submatrices of a 13x8 matrix?
Using this File Exchange tool set, https://www.mathworks.com/matlabcentral/fileexchange/115340-block-transposition-permutation-...

4 years ago | 1

Answered
Plotting graph for specific columns and rows
plot(yourTable{1:4000,20}, yourTable{1:4000,60})

4 years ago | 0

| accepted

Answered
Class implementation such that assignment x=MyObj does in fact x=MyObj.prop1
You can't have precisely what you have asked for, but you can do this, classdef TestClass < handle properties pro...

4 years ago | 0

| accepted

Answered
How to create a rectangular mask based on current code for making an elliptical mask
You could also just use poly2mask. This would avoid the overhead of imrotate. M=256; N=256; %Image dimensions diamMax=60; ...

4 years ago | 1

Answered
How to create a rectangular mask based on current code for making an elliptical mask
I don't understand how your current code works, but you might consider modifying the code below, as appropriate: M=256; N=256...

4 years ago | 0

| accepted

Answered
Backslash does not provided the solution with the smallest 2-norm
In this case, we expect that MATLAB returns the solution x which has the smallest 2-norm, right? No, the backslash operator wil...

4 years ago | 2

| accepted

Answered
How to resample vectors of different length into the same length?
How can I achieve that? You can use interp1 Also should I resample to the biggest size out of the vectors or bring them all to...

4 years ago | 0

Answered
How find the row number for different elements in a column?
As an example, suppose you wanted to find the first occurrence of a 2 in each column. Then one way would be, A=randi(10,10,5) ...

4 years ago | 0

| accepted

Answered
Help with DFT Algorithm (No FFT)
When I carry out this calculation I get the following: . No, because 1/3 of your xx are padded zeros. This will reduce your amp...

4 years ago | 2

| accepted

Question


Using find() is faster than direct logical indexing?
Does it make sense that using find() instead of direct logical indexing is faster in this example: A=randi(100,5e3,5e3); tim...

4 years ago | 1 answer | 1

1

answer

Load more