Answered
Find first item with a certain condition and use it, instead of finding all items with that condition
Process by block, eventually you get the result after a couple of minutes p = zeros(1,100); p(1) = 3; n = 10^10; m = 1e7; ...

5 years ago | 0

Answered
how to find kshortest path or use Dijkstra algorithm for 12 plot points.
Assuming you want to find all paths from 1 to 12, using the code AllPath here, here is the 6 paths with the total distances (euc...

5 years ago | 1

Answered
fminsearch with matrices help
Sort out the dimensions of the matrix before doing anything on paper, programming, etc... >> x=rand(150,3); >> A=rand(3,3) ...

5 years ago | 0

Answered
Combination of choices - recursive function
Recursive method maxsum=16 lo=1; up=Inf; start=5; [~,A] = price(start, lo, up, maxsum) %% function [p, A] = price(sta...

5 years ago | 0

Answered
Combination of choices - recursive function
This is non-recusive approach (recursive is perhaps more scalable) maxsum=16 lo=1; % 2 up=Inf; % 8 start=5; % estimate ...

5 years ago | 1

Answered
Solve as Optimization Problem in Matlab
c=[15 16 17]; t = 121; A = [ c -1; -c -1]; b = [ t; -t]; f = [zeros(length(c),1); 1]; LB = 0*f; x = intlinpr...

5 years ago | 3

Answered
Create a binary matrix for more than 50 variables
fprintf('you need a PC with %1.0f Tb of RAM\n', (2^50*50*8)/1e12)

5 years ago | 0

| accepted

Answered
Cut out all of a square array except for a specified NxN section in the middle.
This works on nd-array, any size (>=m) in all dimension: i = num2cell(floor((size(x)-m)/2)+(1:m)',2) FinalMatrix = x(i{:})

5 years ago | 1

Answered
What is missing from MATLAB #2 - the next decade edition
No big deal but I wish SIGN(X) function could return 1 for X=0 instead of 0. May be implementing an option to not break the comp...

5 years ago | 1

Answered
Generate random number from custom PDF and CDF
This is an exact generation, since the cdf is invertible by close formula: (EDIT1: simplify the code) a = 4; n = 1e6; q = 1...

5 years ago | 1

| accepted

Answered
rearrangement rows of matrices
A = reshape(A,[5 3 5]); A = permute(A,[1 3 2]); A = reshape(A,[5 15]);

5 years ago | 0

| accepted

Answered
I don't know how to prove sin^2(x)+cos^2(x)=1
Definition exp(x) = sum x^k/factorial(k). Property (provable here) exp(x+y) = exp(x)*exp(y) Definitions sin(x) = 1/(2i) (e...

5 years ago | 0

Answered
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.554125e-20.
Try x = A\L you might reduce the cnd to 1e-10, still pretty high. (not N\n, which won't do anything better than inv(N) IMO)

5 years ago | 0

Answered
4 unknown 3 nonlinear equation solution with minimum norm
I change your last equation rhs to 600 (otherwise there is NO solution). Here is two methods to find the minimum norm solution....

5 years ago | 2

| accepted

Answered
The best way to add MATLAB/Simulink plots/figures to a Latex document
I don't know is it's the best but I export to EPS set(fig,'renderer','Painters'); print(fig, 'figurexxx.eps','...

5 years ago | 0

Answered
How to set mutually exclusive arguments in matlab?
function out = twoStats(x,y) arguments x = []; y {MustBeExclusive(x,y)} = []; end % out = ... ...

5 years ago | 0

| accepted

Answered
Bug in patch rendering?
I wouldn't call it a bug, it is just a poorer precision of rendering, wharever causes it (possibly quantification of calculation...

5 years ago | 0

Answered
Hello everyone, I have a question in optimization
The constraint (1c) norm(R11∗*w+r00, Inf) >= rm can be transformed as a union of 42 halfplanes R11(i,:)*w+r00(i,:) >= rm or...

5 years ago | 2

| accepted

Answered
Creating Diagonal Matrix from a Vector
>> g=[1 2 3] g = 1 2 3 >> p=length(g); >> s=10; >> A=full(spdiags(repmat(g,s,1),0:p-1,s,s+p-1)) A = ...

5 years ago | 0

Answered
Function to solve unknowns in Ka=b. Where K is a square matrix fully known, however, knowns and unknowns are scattered in a & b.
You might need to carry out some normalization of a, b so that they are unitless before doing this. % Generate test data m = ...

5 years ago | 0

Answered
Recursion to compute convolution
Here is a hint, you must replace XXX and YYY with something (after all it's your homework) function P = Psum(n, k, alpha) if k...

5 years ago | 1

| accepted

Answered
Can this for-loop be vectorized?
u = setdiff(locs2,locs); % if locs2 is sorted and does not intersect with locs % you can replace u by locs2 steps = interp1(u...

5 years ago | 0

| accepted

Answered
How to use regularization with lsqnonlin function
You are free to incorporation anything in the objective function, e.g., l^2 regularization regcoef = some_small_coef; fun = @(...

5 years ago | 1

| accepted

Answered
multiplying matrix by another matrix element and using it in a command
This must be the fastest if your T is a large vector [P,D] = eig(Q); e = exp(diag(D)*T(:).'); e = reshape(e,1,size(Q,1),lengt...

5 years ago | 0

Answered
Missing patch face color
Check if all your data do not contain NaN, Inf or such. all(isfinite(x(:))) && all(isfinite(yCI95(:))) && all(isfinite(yMean(:)...

5 years ago | 0

| accepted

Answered
subfunction in Matlab or many functions in one edite file
Write them in 2 separate mfiles. Only one function per file (the top one) is visible outside.

5 years ago | 0

Answered
Hello every one, I have a question related to approximation of functions based on norms
l1 and linfinity can be formulate as linear programming, so LINPROG is better.

5 years ago | 1

Answered
Sparse matrix memory usage clarification
MATLAB allocates a larger memory than nnz for sparse matrix, it's call nzmax, with some strategy that is not documented. You sho...

5 years ago | 1

| accepted

Answered
Solving complex integro-differential equation
For omega with imag(omega) < 0, the solution of the integro-differential eqt (dc/dt)(t) = -c(t)/2 * integral_0^inf exp(i*omega*...

5 years ago | 0

| accepted

Load more