Answered

For loop over function handle, how to speed up the code?

If your handle A can accept a matrix as input and the calculation of A(B) is not bottleneck, you can work by chunk % N = 2^16; ...

For loop over function handle, how to speed up the code?

If your handle A can accept a matrix as input and the calculation of A(B) is not bottleneck, you can work by chunk % N = 2^16; ...

23 days ago | 0

Answered

Why tic/toc reports slower times the first five iterations?

If I remember, the JIT optimizer decides to kick in when the same code is detected by execution engine to run few times (5).

Why tic/toc reports slower times the first five iterations?

If I remember, the JIT optimizer decides to kick in when the same code is detected by execution engine to run few times (5).

23 days ago | 1

Answered

MATLAB CODE FOR ROOT MEAN SQUARED

To my book the mean should not be removed in calculation of RMS M = rand(3,100); [rows, columns] = size(M); cal_rms = zeros(r...

MATLAB CODE FOR ROOT MEAN SQUARED

To my book the mean should not be removed in calculation of RMS M = rand(3,100); [rows, columns] = size(M); cal_rms = zeros(r...

23 days ago | 0

Answered

Adding members to a matrix changes other members in the matrix

It is simply the display on screen that scale the data to largest value. The data is untouched interally.

Adding members to a matrix changes other members in the matrix

It is simply the display on screen that scale the data to largest value. The data is untouched interally.

23 days ago | 0

| accepted

Answered

Smoothing/splining data with a limit to the slope of the smooth fit

Using this File Exchange, its is not easy to find a combination of parameters to make it "works". I think it is difficult and th...

Smoothing/splining data with a limit to the slope of the smooth fit

Using this File Exchange, its is not easy to find a combination of parameters to make it "works". I think it is difficult and th...

23 days ago | 0

Answered

How can I compute the Area and the Centroid of the following shape?

xA = 0; xB = 1; a = 9.2; c = 0.5; sfun = @(x)sigmf(x, [a c]); Area = integral(@(x)sfun(x),xA,xB); xc = integral(@(x)...

How can I compute the Area and the Centroid of the following shape?

xA = 0; xB = 1; a = 9.2; c = 0.5; sfun = @(x)sigmf(x, [a c]); Area = integral(@(x)sfun(x),xA,xB); xc = integral(@(x)...

24 days ago | 1

Answered

Minimizing an equation to 0

This minimize the frobenius norm, or l2 norm of the vectorized residual matrix (divided by sqrt(numel(A)) you'll get the rms) k...

Minimizing an equation to 0

This minimize the frobenius norm, or l2 norm of the vectorized residual matrix (divided by sqrt(numel(A)) you'll get the rms) k...

25 days ago | 0

Answered

Why ''int'' and ''integral'' return different answers

I think the problem is more subttle than the simple presence of singularities. Some "mild" singularity can be handlle correctly ...

Why ''int'' and ''integral'' return different answers

I think the problem is more subttle than the simple presence of singularities. Some "mild" singularity can be handlle correctly ...

26 days ago | 0

Answered

How do I plot this set as 3d region in matlab?

Code that plot ALL the boundaries of the domain x = 0; y = 0; c = 1+x^2+y^2; f1 = @(u,v,z) z - (u.^2 + v.^2 + c); f2 = @(...

How do I plot this set as 3d region in matlab?

Code that plot ALL the boundaries of the domain x = 0; y = 0; c = 1+x^2+y^2; f1 = @(u,v,z) z - (u.^2 + v.^2 + c); f2 = @(...

27 days ago | 2

Answered

Randomise vector numbers to maximum variance

A = repmat([10 repmat([repmat(0, 1, 2), 1 repmat(0, 1, 2)], 1, 5)], 1, 20);

Randomise vector numbers to maximum variance

A = repmat([10 repmat([repmat(0, 1, 2), 1 repmat(0, 1, 2)], 1, 5)], 1, 20);

27 days ago | 0

| accepted

Answered

How od i generate random numbers whose sum is constant?

If the numbers are supposed to be >= 0 with precribed sum, a simple method is n = 100; s = 10; Y = -log(rand(1,n)); X = s ...

How od i generate random numbers whose sum is constant?

If the numbers are supposed to be >= 0 with precribed sum, a simple method is n = 100; s = 10; Y = -log(rand(1,n)); X = s ...

27 days ago | 0

| accepted

Answered

How od i generate random numbers whose sum is constant?

Check this out https://uk.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum

How od i generate random numbers whose sum is constant?

Check this out https://uk.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum

27 days ago | 1

Answered

isqnonlin: compute part of objective function outside of matlab

"The gradient vector of the objective function res with respect to the parameters p is calculated like this: d(res)/d(p) = 2*(s...

isqnonlin: compute part of objective function outside of matlab

"The gradient vector of the objective function res with respect to the parameters p is calculated like this: d(res)/d(p) = 2*(s...

28 days ago | 0

Answered

What is the best function of the following shape?

Try this: xmin = 1; xmax = 3; pp = struct('form','pp',... 'breaks',[-1e-100 0 1 inf],... 'coefs',[0 0 0 0 0 0;6,-...

What is the best function of the following shape?

Try this: xmin = 1; xmax = 3; pp = struct('form','pp',... 'breaks',[-1e-100 0 1 inf],... 'coefs',[0 0 0 0 0 0;6,-...

29 days ago | 1

Answered

need general coding/ command to separate matrix data

Try this: % Fake data finalmatrix=sortrows(randi(10,30,3),1) y = finalmatrix(:,1); n=diff(find([true; diff(y)~=0; true])) ...

need general coding/ command to separate matrix data

Try this: % Fake data finalmatrix=sortrows(randi(10,30,3),1) y = finalmatrix(:,1); n=diff(find([true; diff(y)~=0; true])) ...

29 days ago | 0

| accepted

Answered

Replacing Arrays and Matrices

IMO nothing hurts of using same variable name for different things. But my experience tell me that is a bad habit of programmin...

Replacing Arrays and Matrices

IMO nothing hurts of using same variable name for different things. But my experience tell me that is a bad habit of programmin...

29 days ago | 1

Answered

where the jump of the phase function happen?

angle(z) is discontinue at the half line { y=0; x<=0, z=x+1i*y }. The phase jumps from -pi for imaginary part y < 0 to +pi for ...

where the jump of the phase function happen?

angle(z) is discontinue at the half line { y=0; x<=0, z=x+1i*y }. The phase jumps from -pi for imaginary part y < 0 to +pi for ...

30 days ago | 0

Answered

How can I integrate a function related to the modified bessel function of the first kind?

You can also "vectorize" distribution_func by applying arrayfun beta = 5 ; sigma = 1.4/3; integ_func = @(theta,x) x./sigma.^2...

How can I integrate a function related to the modified bessel function of the first kind?

You can also "vectorize" distribution_func by applying arrayfun beta = 5 ; sigma = 1.4/3; integ_func = @(theta,x) x./sigma.^2...

30 days ago | 0

| accepted

Answered

adding counts of ordered pairs

A1=[1 4 3; 3 5 1; 12 4 7; 13 5 2; 14 1 1]; A2=[1 5 1; 13 5 1; 13 7 3; 14 1 5]; A12=[A1; A...

adding counts of ordered pairs

A1=[1 4 3; 3 5 1; 12 4 7; 13 5 2; 14 1 1]; A2=[1 5 1; 13 5 1; 13 7 3; 14 1 5]; A12=[A1; A...

30 days ago | 1

Answered

How to simulate Poisson Distribution Process?

Another way based on exponetial distribution, which is the time between 2 events % Generate n random integers follow Poisson wi...

How to simulate Poisson Distribution Process?

Another way based on exponetial distribution, which is the time between 2 events % Generate n random integers follow Poisson wi...

30 days ago | 0

Answered

Parallel rank calculation for sparse matrices -- suggestions?

For thin and tall sparse matrix A of size (m x n), m>>n and n in the order of 1000s, it might be possible to compute the rank us...

Parallel rank calculation for sparse matrices -- suggestions?

For thin and tall sparse matrix A of size (m x n), m>>n and n in the order of 1000s, it might be possible to compute the rank us...

1 month ago | 0

Answered

How to simulate Poisson Distribution Process?

If you don't have staistics toolbox % Generate n random integers follow Poisson with parameter (==mean) lambda lambda=3; n =...

How to simulate Poisson Distribution Process?

If you don't have staistics toolbox % Generate n random integers follow Poisson with parameter (==mean) lambda lambda=3; n =...

1 month ago | 1

Answered

Fitting a monotonically increasing spline function

One way is to use my https://uk.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation x = [0., 0.75, ...

Fitting a monotonically increasing spline function

One way is to use my https://uk.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation x = [0., 0.75, ...

1 month ago | 1

| accepted

Answered

How to constrain the resulting equation from a polynomial surface fit to a positive range?

This is implementation of Torsen's idea data=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1116665...

How to constrain the resulting equation from a polynomial surface fit to a positive range?

This is implementation of Torsen's idea data=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1116665...

1 month ago | 0

Answered

Using linprog but it's only returning 'Optimal solution found' with no feasible solution?

It looks solution is correct to me. Note that the Aeq = [] meaning you don"t supply equality constraint, so I need to check for...

Using linprog but it's only returning 'Optimal solution found' with no feasible solution?

It looks solution is correct to me. Note that the Aeq = [] meaning you don"t supply equality constraint, so I need to check for...

1 month ago | 0

Answered

Error in finding the angle between three points using atan2

142.9 degree seem right to be. If you don't make the same aspect ratio of x and y with axis equal, angles are deformed on your s...

Error in finding the angle between three points using atan2

142.9 degree seem right to be. If you don't make the same aspect ratio of x and y with axis equal, angles are deformed on your s...

1 month ago | 0

| accepted

Answered

linear independent set formation

t = rand(1,7)*2*pi; independent = rank(cos((0:6)'.*t)) == 7

linear independent set formation

t = rand(1,7)*2*pi; independent = rank(cos((0:6)'.*t)) == 7

1 month ago | 1

| accepted

Answered

Find all paths in a graph with distance, previous nodes

It is not clear what you want to achieve but you might take a look at this function https://uk.mathworks.com/help/matlab/ref/gr...

Find all paths in a graph with distance, previous nodes

It is not clear what you want to achieve but you might take a look at this function https://uk.mathworks.com/help/matlab/ref/gr...

1 month ago | 0

Answered

Interpolating Missing Data with Noise like Brownian Motion

"What might be the best way to do this?'" Interpolation THEN adding noise. There is no reason to mix the noise generation wit...

Interpolating Missing Data with Noise like Brownian Motion

"What might be the best way to do this?'" Interpolation THEN adding noise. There is no reason to mix the noise generation wit...

1 month ago | 0

| accepted

Answered

Rotating a point cloud fails

The last index of this line should be 3 V = rotation_mat*[V1(:,1) V1(:,2) V1(:,2)]'

Rotating a point cloud fails

The last index of this line should be 3 V = rotation_mat*[V1(:,1) V1(:,2) V1(:,2)]'

1 month ago | 0

| accepted