Answered
Indexing a variable using the slice of another matrix
Your original loop, for i = 1:numel(river_discharge_per_channel) % 4.4e6 values (very long daily time series) [~,index] = ...

5 years ago | 2

| accepted

Answered
how to segment the gray scale image from background
If you're trying to develop a binary map of the horses, I was able to do so decently using the Image Segmenter app: https://www...

5 years ago | 0

| accepted

Answered
How can I take two inputs from the same variable
When the Slider is moved, its callback will be invoked. You should set the EditField value in the callback to keep them consiste...

5 years ago | 0

| accepted

Answered
How to include an nonlinear equality constraint when using surrogateopt
Another solution might be to re-arrange your nonlinear equality constraint in the form, 3*cap*(days-4) - (fill+cap)=0 Althoug...

5 years ago | 0

Answered
Avoid using for-loop to create sparse Jacobian (or how to efficiently offset each row of a matrix by a different value)
N=5; vals=rand(N,4); %Fake Jacobian values. [I,J]=ndgrid(1:N,1:4); J=J+(0:N-1).'*3; Jacobian=sparse(I(:),J(:), val...

5 years ago | 1

| accepted

Answered
Crop matrix based on entries
A=[0,0,0,0,0,0,0,0,0,0; 0,0,0,0,0,0,0,0,0,0; 0,0,0,0,0,0,0,1,0,0; 0,0,1,0,0,0,0,0,0,0; 0,1,1,1,0,0,0,0,0,0; 0,0,0,1,0,...

5 years ago | 0

| accepted

Answered
How to generate 0 and 1 matrix in specific condition.
Using the attached file sortlidx, m=4; n=15; A=[ones(1,n);randi([0,1],m-1,n)]; [~,idx]=sortlidx(rand(m,n),1); A=A(idx)...

5 years ago | 0

| accepted

Answered
How to include an nonlinear equality constraint when using surrogateopt
Your nonlinear equality constraint is, days= ((fill+cap)/(cap*3))+4; In order for this to be satisfied, all terms on the right...

5 years ago | 0

Answered
Patch won't fill my polygon and inpolygon won't find points inside
Aside from what others have said, your hhx and hhz data does not define a polygon, but rather two polygons. I supsect that this ...

5 years ago | 0

Answered
What interpolation method is used to solve this problem?
this is an example problem just been created to understand and i am searching for an approach or methods to solve this kind of p...

5 years ago | 1

| accepted

Answered
In a cell array, how I can count the number of cells in each column?
cellfun('length',locs)

5 years ago | 1

| accepted

Answered
Add operation is too slow
vd=[1 2 3]; bd=[4 5 6 7]; N=max(numel(vd), numel(bd)); vd(end+1:N)=0; bd(end+1:N)=0; d=vd+bd

5 years ago | 0

Answered
Shorting dissimilar Elements from an Array
A=1:20; B= [10 9 2 4 7 16 17 15 11 13]; C=setdiff(A,B)

5 years ago | 1

| accepted

Answered
Query property on a line that was fitted using X,Y
Yes, this page talks about customizing the datatip: https://www.mathworks.com/help/matlab/creating_plots/create-custom-data-tip...

5 years ago | 0

Answered
inpolygon function within forloop help
I don't see anything wrong with your code, but this might be simpler: m=numel(x_bin_edges)-1; n=numel(y_bin_edges)-1; [~,~,~...

5 years ago | 0

| accepted

Answered
Min and max circles from best fitted circle.
radii= vecnorm([x(:)-xhat,y(:)-yhat],2,2); rmin=min(radii); rmax=max(radii); plot(raadius*cos(nurgad)+xhat,raadius*sin(nu...

5 years ago | 0

| accepted

Answered
Using Multistart with constrainted fmincon
problem = createOptimProblem('fmincon', 'objective', fun, 'x0', [pi/11, pi/7, pi/6, pi/3],'Aineq', [1, -1,0,0;0, 1, -1, 0; 0,0...

5 years ago | 0

| accepted

Answered
How to convert zero to 'Nan' for multiple dot mat file containing 1d data
fnames=ls('NormFHR*.mat'); for i=1:size(fnames,1) fn=fnames(i,:); s=load(fn); A=s.x; A(~A)=na...

5 years ago | 1

| accepted

Answered
How to generate a sparse matrix for a given array?
B=laplacian( graph(A(:,1),A(:,2)) );

5 years ago | 0

| accepted

Answered
Root solving an integral of an exponential function
Perhaps this is what you meant, syms x t fun = (exp(t.^2)-1)/t; f=matlabFunction( int(fun,0,x) - 0.1 ); x=fzero(f,0.5)

5 years ago | 0

Answered
parfor variable classification issue
map is a sliced variable, so it can only be indexed using the loop variable. map = zeros(i1max - i1min + 1,j1max - j1min + 1,3)...

5 years ago | 1

| accepted

Answered
Find repeated values in an array, by column and rows (unique function).
A = [9.04828 8.80036 ; 9.04828 8.80036 ; 9.11259 8.74653 ; 9.04828 8.80036 ; 9.24358 8.74653 ; 8.9823 9.05449 ; 9.02563 8....

5 years ago | 0

Question


Ordering of OptimizationVariables in an OptimizationProblem
When I use the problem-based optimization framework to create an OptimizationProblem, e.g., r=optimvar('r',5,'LowerBound',0,'Up...

5 years ago | 0 answers | 1

0

answers

Answered
Use kron to build a matrix
No, the matrix you've shown is not a Kronecker product, but the matrix is easily generated using diff, e.g., A=full(diff(speye(...

5 years ago | 0

| accepted

Answered
Optimizing two vectors of different sizes
r=optimvar('r',n,'LowerBound',0,'UpperBound',1); B= optimvar ('B', m); [p,idx]=prob2matrices({r, B},'Constraints', sum(r)<=1);...

5 years ago | 0

| accepted

Answered
Find the first element that satisfies a condition on 3D data
S = sort(prec,3,'descend'); % 360x150x365 matrix SC = cumsum(S,3,'omitnan'); % 360x150x365 matrix p_annual = SC(:,:,e...

5 years ago | 0

| accepted

Answered
Split a Number Sequence into n equal parts and then replacing the values in the matrix.
result = discretize(A, linspace(0, max(A(:)), 4) )-1

5 years ago | 3

| accepted

Answered
How can I update point positions
If the plot was generated with h=scatter3(__) you can just change h.XData, h.YData, and h.ZData.

5 years ago | 0

Answered
Error when using variable in axis
Must be caused by subs probably Yes, subs() does not give numeric output. You must convert it to numeric with double() or simi...

5 years ago | 0

| accepted

Answered
Cellfun for mean squared error
Seems like you could do the whole thing in one line with, data_avg = immse( cell2mat(data(:,1)) , cell2mat(data(:,2)) );

5 years ago | 0

| accepted

Load more