Answered

interpn vs griddata: how are results different?

Mathematical, in short the difference is INTERPN uses tensorial linear function on nd-hypercube that enclose the query point. ...

interpn vs griddata: how are results different?

Mathematical, in short the difference is INTERPN uses tensorial linear function on nd-hypercube that enclose the query point. ...

alrededor de 13 horas ago | 0

Answered

Usage of structure as input of a function. Is it efficient ?

"I've struggled to find ressources online about that matter (maybe I didn't find the right keywords" No, it's not your fault, T...

Usage of structure as input of a function. Is it efficient ?

"I've struggled to find ressources online about that matter (maybe I didn't find the right keywords" No, it's not your fault, T...

alrededor de 16 horas ago | 0

Answered

Find/return value from each row in a big matrix that corresponds with a condition/value

"Let me specify, I only want the first time the value appears in each row and if the value dont appear I want closest value." T...

Find/return value from each row in a big matrix that corresponds with a condition/value

"Let me specify, I only want the first time the value appears in each row and if the value dont appear I want closest value." T...

alrededor de 18 horas ago | 0

Answered

Convert subscripts to linear indices with dynamic matrix size

% Generate random array of nd-indexes sz=[3 4 5 6]; m = 10; n = length(sz); SUBIDX=ceil(sz.*rand(m,n)); % Method 1, with ...

Convert subscripts to linear indices with dynamic matrix size

% Generate random array of nd-indexes sz=[3 4 5 6]; m = 10; n = length(sz); SUBIDX=ceil(sz.*rand(m,n)); % Method 1, with ...

alrededor de 19 horas ago | 1

| accepted

Answered

Vectorize a code involving multiple loops commands

x = [0:0.1:10]; a=[2 1; 0.5 0.25]; b=[500 200; 300 250]; c=[0.25 0.35; 0.15 0.25]; d=[0.5]; X = reshape(x,1,1,[]); AB = ...

Vectorize a code involving multiple loops commands

x = [0:0.1:10]; a=[2 1; 0.5 0.25]; b=[500 200; 300 250]; c=[0.25 0.35; 0.15 0.25]; d=[0.5]; X = reshape(x,1,1,[]); AB = ...

alrededor de 22 horas ago | 1

| accepted

Answered

Conditional Random number generation

m = 5; n = 3; s = 10; This will generate uniform distribution with sum criteria % generate non-negative integer random (m x ...

Conditional Random number generation

m = 5; n = 3; s = 10; This will generate uniform distribution with sum criteria % generate non-negative integer random (m x ...

1 día ago | 0

Answered

Rounded random numbers with fixed sum

k = 3; r = (diff([0 sort(randperm(100+k-1,k-1)) 100+k])-1)/100

Rounded random numbers with fixed sum

k = 3; r = (diff([0 sort(randperm(100+k-1,k-1)) 100+k])-1)/100

1 día ago | 0

Answered

mex-file crashes MATLAB in for loop

Those are wrong, you should not Free the pointers that you are not Malloc. mxFree(a_double); mxFree(b_double); mxFree(z_do...

mex-file crashes MATLAB in for loop

Those are wrong, you should not Free the pointers that you are not Malloc. mxFree(a_double); mxFree(b_double); mxFree(z_do...

1 día ago | 1

| accepted

Answered

C = union( A,B ) is too slow. Is there any faster way given that A and B are ordered.

If you have a decend C-compiler you might use my MEX MERGE SORTED ARRAY c = mergesa(a,b); % or mergemex(a,b); c = c([true; dif...

C = union( A,B ) is too slow. Is there any faster way given that A and B are ordered.

If you have a decend C-compiler you might use my MEX MERGE SORTED ARRAY c = mergesa(a,b); % or mergemex(a,b); c = c([true; dif...

1 día ago | 1

| accepted

Answered

Recover matrix Z from XZX', Z es symmetric and n-by-n, while X is k-by-n where n>>k

You can't getback to 27x27 covariance matrix Z after reducing it it on 5 dimensional space (by X). The information lost forevver...

Recover matrix Z from XZX', Z es symmetric and n-by-n, while X is k-by-n where n>>k

You can't getback to 27x27 covariance matrix Z after reducing it it on 5 dimensional space (by X). The information lost forevver...

2 días ago | 0

Answered

solve A*X=B containing very large or small elements

Work with unitless system, scale your matrix, or use automatic scaling if you don't want to bother.

solve A*X=B containing very large or small elements

Work with unitless system, scale your matrix, or use automatic scaling if you don't want to bother.

2 días ago | 0

| accepted

Answered

How do I shift columns (left or right) in a matrix

k > 0 shift right k < 0 shift left A*diag(ones(1,size(A,2)-abs(k)),k)

How do I shift columns (left or right) in a matrix

k > 0 shift right k < 0 shift left A*diag(ones(1,size(A,2)-abs(k)),k)

2 días ago | 0

Answered

How to solve the equation of binary logic operation, where all unknowns are 0 or 1

[x1,x2,x3,x4,x5,x6]=ndgrid(0:1); x1 = x1(:); x2 = x2(:); x3 = x3(:); x4 = x4(:); x5 = x5(:); x6 = x6(:); b = [x1+x2+x3+...

How to solve the equation of binary logic operation, where all unknowns are 0 or 1

[x1,x2,x3,x4,x5,x6]=ndgrid(0:1); x1 = x1(:); x2 = x2(:); x3 = x3(:); x4 = x4(:); x5 = x5(:); x6 = x6(:); b = [x1+x2+x3+...

3 días ago | 0

Answered

Finding the most orthogonal set of n vectors from dataset of unit vectors

I propose this % random test A, which represents 100 normalized vector in R^5 n = 5; m = 100; A = randn(n,m); A = A ./ sqrt...

Finding the most orthogonal set of n vectors from dataset of unit vectors

I propose this % random test A, which represents 100 normalized vector in R^5 n = 5; m = 100; A = randn(n,m); A = A ./ sqrt...

3 días ago | 0

Answered

EVALIN cannot execute a return?

Yes it is written in the doc. From EVALIN/EVAL document page "evalin(workspace,expression) ... expression — Expression to ev...

EVALIN cannot execute a return?

Yes it is written in the doc. From EVALIN/EVAL document page "evalin(workspace,expression) ... expression — Expression to ev...

4 días ago | 1

| accepted

Answered

Matrix compare and unkonw relationships to find

Use regression methods. If you have a linear/affine model, then use linear algebra. If you have "kind" non-linear, use polynomia...

Matrix compare and unkonw relationships to find

Use regression methods. If you have a linear/affine model, then use linear algebra. If you have "kind" non-linear, use polynomia...

4 días ago | 0

Answered

Why is memory reduced for an identical copy of a sparse array?

Nah nothing to do with name length, it's the number of internal non zeros of ('Ir" and "Pr" old notation) array reserved by MATL...

Why is memory reduced for an identical copy of a sparse array?

Nah nothing to do with name length, it's the number of internal non zeros of ('Ir" and "Pr" old notation) array reserved by MATL...

4 días ago | 1

| accepted

Answered

(Block-) Matrix multiplication inaccuracy

Same problem, don't count on exact associativity when working with floating point arithmetics. I can quote word-to-word from wha...

(Block-) Matrix multiplication inaccuracy

Same problem, don't count on exact associativity when working with floating point arithmetics. I can quote word-to-word from wha...

4 días ago | 0

| accepted

Answered

Reshape n-th dimension of an array

You operation makes the array changing its size, you can't use for-loop to store the rotated page in the SAME arrray. And btw f...

Reshape n-th dimension of an array

You operation makes the array changing its size, you can't use for-loop to store the rotated page in the SAME arrray. And btw f...

4 días ago | 1

| accepted

Answered

Curl, Divergence calculation from velocity data

Your data is already gridded, no need to gridded on top of it load('matlab.mat') UU=reshape(data(:,3),[75 62]); VV=reshape(...

Curl, Divergence calculation from velocity data

Your data is already gridded, no need to gridded on top of it load('matlab.mat') UU=reshape(data(:,3),[75 62]); VV=reshape(...

4 días ago | 0

Answered

Checking a matrix for duplicates in specific row, removing the respective columns

d= [1 2 2 3 4 5 6 6 7; 1 2 3 4 5 6 7 7 8] dd = diff([nan,d(1,:),nan])==0; remove = dd(1:end-1) | dd(2:end) x_cut = uni...

Checking a matrix for duplicates in specific row, removing the respective columns

d= [1 2 2 3 4 5 6 6 7; 1 2 3 4 5 6 7 7 8] dd = diff([nan,d(1,:),nan])==0; remove = dd(1:end-1) | dd(2:end) x_cut = uni...

5 días ago | 0

| accepted

Answered

Interpolating at vertices of a mesh

In theory you cannot. A function that is piecewise constant on elements is discontinuos at the vertices and you cannot speak ab...

Interpolating at vertices of a mesh

In theory you cannot. A function that is piecewise constant on elements is discontinuos at the vertices and you cannot speak ab...

5 días ago | 0

Answered

Obtain the mean angle (circle mean of a file)

angledata_deg is your angle data in degree meanangle_deg = rad2deg(atan2(mean(sind(angledata_deg),2),mean(cosd(angledata_deg),2...

Obtain the mean angle (circle mean of a file)

angledata_deg is your angle data in degree meanangle_deg = rad2deg(atan2(mean(sind(angledata_deg),2),mean(cosd(angledata_deg),2...

6 días ago | 0

| accepted

Answered

How parentheses effects multiplication with pi ?

From wikipedia "While floating-point addition and multiplication are both commutative (a + b = b + a and a × b = b × a), they a...

How parentheses effects multiplication with pi ?

From wikipedia "While floating-point addition and multiplication are both commutative (a + b = b + a and a × b = b × a), they a...

6 días ago | 0

| accepted

Answered

Adding zeros to matrix

% Replace this with your image Image100 = peaks(100)+10; %Centering padding in 4 sides PadImage300 = zeros(300,300,size(Ima...

Adding zeros to matrix

% Replace this with your image Image100 = peaks(100)+10; %Centering padding in 4 sides PadImage300 = zeros(300,300,size(Ima...

6 días ago | 0

| accepted

Answered

How to create a surface with random spheres protruding?

Is this you want? x = linspace(0,1); y = linspace(0,1); [X,Y] = meshgrid(x,y); Z = zeros(size(X)); N = 30; for k=1:N ...

How to create a surface with random spheres protruding?

Is this you want? x = linspace(0,1); y = linspace(0,1); [X,Y] = meshgrid(x,y); Z = zeros(size(X)); N = 30; for k=1:N ...

6 días ago | 0

| accepted

Answered

Integral calculation using matlab

Feel free to change these hyper-parameters n = 3 k = 2*pi*rand() integral(@(phi) arrayfun(@(phi) abs(integral(@(theta) exp(...

Integral calculation using matlab

Feel free to change these hyper-parameters n = 3 k = 2*pi*rand() integral(@(phi) arrayfun(@(phi) abs(integral(@(theta) exp(...

7 días ago | 0

| accepted

Answered

Combining function handles into one function handle

a = @(x) x(1)^2+x(2)^2; b = @(x) x(3)^2-x(4)^2; c = @(x) x(1)*x(4); % suppose your for-loop puts each function handle in a ...

Combining function handles into one function handle

a = @(x) x(1)^2+x(2)^2; b = @(x) x(3)^2-x(4)^2; c = @(x) x(1)*x(4); % suppose your for-loop puts each function handle in a ...

7 días ago | 0

Answered

I cannot find the distance between two matrices with respect to the Frobenius inner product.

Distance in frobenius scalar product: dist_AB = norm(A - B, 'fro') which is the same as this norm(A(:)-B(:),2)

I cannot find the distance between two matrices with respect to the Frobenius inner product.

Distance in frobenius scalar product: dist_AB = norm(A - B, 'fro') which is the same as this norm(A(:)-B(:),2)

7 días ago | 0

| accepted

Answered

Indexing problem with matrices

A = [3 5 9 6 ; 2 1 13 6 ; 6 8 52 4 ; 13 6 8 22 ]; GRID = [linspace(1,100,100); rand(1,100); rand(1,100)]' Code [tf,loc]=ismem...

Indexing problem with matrices

A = [3 5 9 6 ; 2 1 13 6 ; 6 8 52 4 ; 13 6 8 22 ]; GRID = [linspace(1,100,100); rand(1,100); rand(1,100)]' Code [tf,loc]=ismem...

7 días ago | 0

| accepted