Answered
evaluate curve fit sum of sine
The cfit object returned by fit() can be used as a function handle, to evaluate the fitted function at any desired query points....

5 years ago | 0

Answered
How can I use while loops to determine if an element is larger than the element below it and store the results in a vector with 1 representing true and 0 representing false?
A=randi([0 9],1,10)'; n=numel(A)-1; B=zeros(n,1); i=1; while i<=n if A(i)>A(i+1) B(i,1)=true; else ...

5 years ago | 1

| accepted

Answered
Multiple Values for one variable with for loop
No need for a loop. Just use discretize(). Grades=["P" "M" "D"]; x = [80 50 70 60 50 90]; binNumber=discretize(x,[-inf,60...

5 years ago | 0

| accepted

Answered
how can I create a monochrome image with a resolution of 128x128 pixels consisting of horizontal white and black stripes 2 pixels wide
stripeWidth = 2; imageRows = 256; % Whatever... imageColumns = 256; % Whatever... wholeImage=true(imageRows/stripeWidth,...

5 years ago | 0

Answered
how can I create a monochrome image with a resolution of 128x128 pixels consisting of horizontal white and black stripes 2 pixels wide
stripeWidth = 2; imageRows = 256; % Whatever... imageColumns = 256; % Whatever... wholeImage=true(imageRows,imageColumns...

5 years ago | 0

Answered
how can I create a monochrome image with a resolution of 128x128 pixels consisting of horizontal white and black stripes 2 pixels wide
stripeWidth = 2; imageRows = 256; % Whatever... imageColumns = 256; % Whatever... oneLine=ones(stripeWidth,imageColumns)...

5 years ago | 0

| accepted

Answered
Using interp2 for several functions
fCell = {f1,f2,...,fn}; n=numel(fCell); G=griddedInterpolant({y,x},fCell{1}); test=cell(1,n); for i=1:n G.V...

5 years ago | 0

Answered
How to extrapolate a curve using a data set?
If your curve is a polynomial, then polyfit is definitely the best, but you can also look at fit, nlinfit, lsqcurvefit, spline, ...

5 years ago | 1

| accepted

Answered
Intersection point of line whose equation is known and curve defined by data points.
Use fzero to find the root of the difference, Line - Curve

5 years ago | 0

Answered
The Nonlcon are not satisfied by GA
You have not passed in a nonlinear constraint function handle in your call to ga. Only lb and ub bounds are specified: ga(fun,3...

5 years ago | 1

| accepted

Answered
Different groups of 1s
Using the tools in this File Exchange submission, https://www.mathworks.com/matlabcentral/fileexchange/78008-group1s?s_tid=srch...

5 years ago | 1

Answered
how to increase the run time of the matrix ?
The best option might be to use Matlab's own shortestpath routine, https://www.mathworks.com/help/matlab/ref/graph.shortestpath...

5 years ago | 0

Answered
Select random numbers form matrix
With repetition: Use randi() Without repetition: Use randperm()

5 years ago | 0

| accepted

Answered
Average of a each vertical section of a stepped sawtooth wave
I would fit a line to the steps with polyfit, then find the intersections of the line fit with the vertical edges.

5 years ago | 1

| accepted

Answered
Plotting using fimplicit and plot in the same figure
Your code is correct. The two plots are so similar that you cannot see them as distinct curves unless you zoom in.

5 years ago | 0

| accepted

Answered
auto image registration takes too long
You should do an initial test of the different 90/180 degree flip combinations to see which re-orientation best agrees with the ...

5 years ago | 0

| accepted

Answered
Remove outside lines from the image
Can't you just pre-delete the edge values? BW1([1:10,end-9:end], [1:10,end-9:end]) = 0; Or, use imclearborder().

5 years ago | 0

| accepted

Answered
Extend a matrix diagonally
See Create A Sparse Tridiagonal Matrix.

5 years ago | 0

Answered
how to integral f(x).*g(x)
f = 0.05:0.05:0.4; % t=0:.01:20; X=@(t) cos(2*pi*f*t); Y=@(t) cos(2*pi*f*t); g=@(t) X(t).*Y(t); I = integral(g,0,20,'Ar...

5 years ago | 0

| accepted

Answered
Extend a matrix diagonally
No need for a loop: n=9; result=toeplitz([2 1 zeros(1,n-2)]) n=11; result=toeplitz([2 1 zeros(1,n-2)])

5 years ago | 0

Answered
Interpolating unknown values in a 3D matrix
If you've done the fitting, why can't you just evaluate it at the x,y of interest?

5 years ago | 0

| accepted

Answered
Using Vector Components in Functions
Pass X to the function as an additional input, function xcoeff = xcoeff(a,b,X)

5 years ago | 1

| accepted

Answered
Setting a Constraint on a Coefficient Factor
Yes, remove all negative values from f, and the corresponding columns from the constraint matrices. keep=(f>0); f=f(keep); ...

5 years ago | 1

| accepted

Answered
Growing Diagonal Matrix Problem
A=3; B=4; M=[A B 0; B A B; 0 B A]; n=3; e = ones(n,1); Q = spdiags([e 0*e e],-1:1,n,n); %Q=toeplitz(sparse([0,1,zeros(...

5 years ago | 0

Answered
How to write a summation term within minimization function such as lsqnonlin?
You won't implement the summation. lsqnonlin or lsqcurvefit implements thd sum of squares for you. Your job is to compute a vect...

5 years ago | 0

| accepted

Answered
How is the dataindex from the datacursormode calculated?
In a 2D plot, the dataindex i is almost certainly the one such that XData(i),YData(i) is closest to where you clicked.

5 years ago | 0

Answered
Finding a centre and plotting a sphere
Maybe you can use minboundsphere, distributed at, https://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of-minimal...

5 years ago | 0

Answered
Using for loop to access two elements from array
Forget the loop. It's a four-line operation: str='abc'; bits=reshape( dec2bin(str,8).' ,1,[]) -'0'; %converts string from de...

5 years ago | 0

Answered
Curve of best fit doesn't show on the graph plot although plot function is written
The first row of your data table contains NaNs. They must be removed, so as not to confuse polyfit. load(websave('t','https://w...

5 years ago | 0

| accepted

Answered
Fmincon / Multistart: Local minimum found, but one nonlinear constraint is violated
If the exit message says constraints were satisfied within tolerance, then that is what should have happened. However, the toler...

5 years ago | 0

| accepted

Load more