Answered
The best way to write a large number of constraints for an optimization problem
If they are linear constraints, they will be expressed using matrix-vector multiplication A*x<=b Aeq*x<=beq so any vectorized...

9 days ago | 0

| accepted

Answered
How do I remove NaN values from a cell array?
The presence of NaNs isn't the problem. The problem is that the cell contents are character vectors of different lengths. You ca...

9 days ago | 0

| accepted

Answered
Fmincon linear contraint doens't work in my case
You should check the EXITFLAG output to see if fmincon believes it converged. If it did converge, the ranges should be satisfied...

10 days ago | 0

| accepted

Answered
How can i create a convolution using toeplitz matrix?
Consider >> x=1:5, y=rand(1,5), x = 1 2 3 4 5 y = 0.2899 0.4714 0.8782 0.6555 ...

10 days ago | 0

| accepted

Answered
fminunc: get Hessian approximation after each iteration
You could try running fminunc 1 iteration at a time in a for-loop and saving the 6th output arguments, options.MaxIter=1; ...

10 days ago | 0

| accepted

Answered
Using FFT in for-loop is extremely slow - how to accelerate?
To conserve memory, I only store the results for x,y,z inside the mask. It would be straightforward to re-embed them in 4D array...

10 days ago | 0

Answered
Can someone propose some code that will "connect the dots" to produce the correct geometric shapes (i.e., hexagons, pentagons, rectangles) from these points?
Here is a refinement of my earlier answer which I think performs better. It uses the attached classdef file to create objects re...

11 days ago | 1

Answered
Create matrix (30 x 12) with numbers from 1 to 12 without repetition without any repetitions of following numbers for each row
Note that there are only >> nchoosek(12,2)*2 ans = 132 distinct subsequences of length 2 that can be drawn from the numbe...

11 days ago | 0

Answered
Can someone propose some code that will "connect the dots" to produce the correct geometric shapes (i.e., hexagons, pentagons, rectangles) from these points?
This seems to do it. For the display part, it uses plotpts2d, which you've seen before. maxDistLine=10; %User tolerance s...

13 days ago | 0

| accepted

Answered
Data: Interp1 spline and cubic method
how would you approximate this data using the Interp1 function and spline method For example, year=[1;2;3;4;5;6;7;8;9;10]; po...

14 days ago | 1

| accepted

Answered
Can I set restrictions on the output matrix from "linprog" before solving?
If X is constrained to be binary (using intlinprog rather than linprog), then this condition is equivalent to the linear inequal...

15 days ago | 0

Answered
Derivative constraint in curve fitting
You can do spline fits with those kinds of constraints using this, https://www.mathworks.com/matlabcentral/fileexchange/24443-s...

15 days ago | 1

Answered
Why parfor could read the deleted script?
Remember that in a parfor loop, you are responsible for ensuring that no operations in the loop that depend on the order of exec...

15 days ago | 0

| accepted

Answered
Converting 3D matrix to a bigger 2D matrix efficiently
[ma,na,~]=size(A); B=permute(reshape(A,ma,na,2,2), [4,1,3,2]); B=reshape(B,2*ma,2*na)

16 days ago | 1

| accepted

Answered
Converting 3D matrix to a bigger 2D matrix efficiently
Is there an efficient way to create the B matrix without using loops? There is nothing inefficient about using loops in this ca...

16 days ago | 2

Answered
How to check the internal solution results of Fsolve to know where the matrix dimension assignment has problem?
Yes, if you re-run your code after executing >> dbstop if caught error at the command line, the code will pause execution at t...

16 days ago | 1

| accepted

Answered
Unable to perform assignment because brace indexing is not supported for variables of this type.
grade = cell(1,length(fish)); price = cell(1,length(fish)); use = cell(1,length(fish)); % preallocate cell array. Also, these...

17 days ago | 0

Answered
matrix multiplication without declaring the destination matrix first
You can loop backwards. Then the pre-allocation will be done silently. clear C2 for i = N:-1:1 for j = N:-1:1 fo...

17 days ago | 0

Answered
lsqcurvefit add a constraint
No, you cannot supply any constraints except simple bounds with lsqcurvefit. You do need to use fmincon. Write an objective func...

17 days ago | 0

Answered
Take average of the nearest n pixels
If you have the Statistics Toolbox, you could use knnsearch, https://www.mathworks.com/help/stats/knnsearch.html

18 days ago | 0

| accepted

Answered
Parameter estimation - estimate integers only
If your objective and constraints are linear, you can use intlinprog. Otherwise, if you have the Global Optimization Toolbox, an...

18 days ago | 0

Answered
chane .fig extension to .jpg
saveas(fighandle,'filename.jpg')

18 days ago | 0

Answered
fmincon to get 3 unknown parameters
As the error message says, your objective function must return a scalar value and does not. It returns a length 12 vector. The v...

18 days ago | 0

Answered
what is the differences between "sum(x, 3, 'omitnan')" and "nansum(x, 3)" ?
Nothing. In earlier versions of Matlab, the 'omitnan' flag wasn't available to the sum command, so you had to either use nansum ...

18 days ago | 1

Answered
Define a Non linear objective function with 2 decision variables
If you have R2109a or higher, the general set-up could be done like this. For simplicity, I demonstrate using a least squares ob...

18 days ago | 0

| accepted

Answered
optimoptions ga error - "Invalid solver specified"
That might happen if you have attempted this on a new Matlab installation which doesn't have the Global Optimization Toolbox ins...

18 days ago | 0

| accepted

Answered
Split an image into two sets
N=numel(yourImage); indices=randperm(N,round(N/2)); A=yourImage(indices); B=yourImage; B(indices)=[];

19 days ago | 2

Answered
FMINUNC cannot continue help?
You forgot to pass your params, fobj = @(beta)myobj(beta,params); function [err, T, Y] = myobj(beta,params) ...

21 days ago | 0

| accepted

Answered
Diagonal matrices with spdiags
s=0.12; N_r=30; r=linspace(0,1,N_r)'; dr=r(2); r_plus=r+0.5*dr; r_minus=r-0.5*dr; a_plus=s*r_plus(1:end-1).^2; a_minus=s*...

21 days ago | 0

| accepted

Answered
Approximation coefficients differencies when function fit and Fitting Curve are used
What is "Fitting Curve"? Do you mean the Curve Fitting app? Why do you think the fit function uses different starting points tha...

21 days ago | 0

Load more