Answered
How to simplify this and make it efficient
NOTE: what a messy and bad data structure. There might be a much better way than working cell of structs and table. % Generate...

6 years ago | 2

| accepted

Answered
How to calculate all permutations of a vector that satisfy a given condition
If your vector is consecutive number, you can directly use this allVL1 in the File Exchange. Otherwise you can adapt the subfun...

6 years ago | 2

| accepted

Answered
how to do left and right bit rotation
% Test example, 166 corresponds to your example of binary '10100110' M=[2 32 45; 3 54 166; 134 245 69] rotfun = @(M...

6 years ago | 0

| accepted

Answered
Best way to calculate the determinants of a series of matrices?
I reverse the order and put the page in third dimension (avoid to use squeeze). For small size, you can save CPU time by 4 fold...

6 years ago | 2

| accepted

Answered
How to 2D plot using the equation of fi and zi?
The wikipedia page plots only the polar sector 2*pi/(2*n) of the stream lines / potential The second plot is the full picture....

6 years ago | 0

| accepted

Answered
reshape 3d to 2d array
Not RESHAPE, but PERMUTE (there is movement in internal storage, and it more expansive than RESHAPE) A = permute(A, [3 2 1]);

6 years ago | 1

Answered
How to set a range for a random 4x3 Matrix
In principle it can reach -10/+10 with tiny strict positive probability, but won't cover interval with a fine density x = ((ran...

6 years ago | 0

Answered
How to set a range for a random 4x3 Matrix
Inclusive and float x = max(min(((rand(4,3)-0.5)*20)*1.001,10),-10) you get 1/1000 chance to hit -10/+10

6 years ago | 0

Answered
Joint Histogram 2 D
% Test data A = imread('ngc6543a.jpg'); red=A(:,:,1); green=A(:,:,2); h = accumarray([green(:),red(:)]+1,1,[256 256]);

6 years ago | 0

Answered
Joint Histogram 2 D
% Test data A = imread('ngc6543a.jpg'); red=A(:,:,1); green=A(:,:,2); % h = histcounts2(green,red,256); % compute % or pl...

6 years ago | 0

| accepted

Answered
Generate random Bistochastic matrix with zero diagonals
For small n (up to 7/8), use RANDFIXEDSUM function on FEX n = 5; % size of matrix % This must be done once if n doesn't chan...

6 years ago | 0

Answered
Finding the common range between two ranges
You can use this RangeIntersection function on FEX % Test data X1=[0.316227766016838 0.346410161513775 0.509901951359279 0.52...

6 years ago | 0

| accepted

Answered
minimiztion the distance travel
Checkout function distances Warning : Your adjacent matrix is not symmetric ! >> A A = 0 2 100 2 10 ...

6 years ago | 0

| accepted

Answered
How to use randperm with minimum spacing between random numbers
n=20; k=3; b=7; [as,is]=sort(randperm(n-(k-1)*(b-1),k)); % if it throws an error then b/k/n are not compatible a = as + (0...

6 years ago | 2

Answered
Find series of maxima of array (and matrix) within blocks of size n
maxfun = @(A) squeeze(max(reshape(A,size(A,1),5,[]),[],2)); A = [1 2 5 1 0 0 5 0 1 2 4 0 5 3 2 0 1 0 0 5] B = maxfun(A) ...

6 years ago | 1

Answered
How to sum matrices together when within a structure
linear_RL_broadband = sum(cat(3,linear.linear_RL_sum),3)

6 years ago | 0

| accepted

Answered
How to calculate the average gradient of an image?
AG=abs((sum(sum(mode(Gmag))/(sqrt(2))))) I can't see the denominator factor (H-1)*(W-1). And Why you use MODE? Those two error...

6 years ago | 0

Answered
make header from numeric array
hdr = arrayfun(@(x) sprintf('L_conv_%f', x), wl_arr, 'unif', 0)

6 years ago | 0

| accepted

Answered
matrix to cell convert?
Depending on what you want as organization, either C = mat2cell(reshape(A,4*64,4*64),4*ones(1,64),4*ones(1,64)) or C = reshap...

6 years ago | 2

Answered
Matlab fit to three dimensions function
n = length(y); A = [ones(n,1) x1(:) x2(:) x3(:) x1(:).^2 x2(:).^2 x3(:).^2 x1(:).*x2(:) x1(:).*x3(:) x2(:).*x3(:)] \ y(:)

6 years ago | 0

Answered
Solving a set of linear equations using vectorization
P = 40000; dP = 0:10:40 % what ever z = zeros(size(dP)); A = [1 1 1;10 28 40;144 -240 180]; B = [-P+z; -dP; z]; F = A \ B

6 years ago | 0

Answered
3D Array Multiplication with 2D Matrix
Simply do (R2016b or later) data1 = data1 .* data2(:)

6 years ago | 1

Answered
Use of cellfun to obtain the 2 element ONLY
>> c={'A1' 'A2' 'A3' 'A4' ''} c = 1×5 cell array {'A1'} {'A2'} {'A3'} {'A4'} {0×0 char} This throw a...

6 years ago | 0

Answered
how to stack 2 dimensional arrays into 3 dimensional aarays?
If 2D arrays are stored in 9 variables cat(3,A1,A2,A3,A4,A5,A6,A7,A8,A9); If they are stored in 1x9 cell C cat(3, C{:});

6 years ago | 2

| accepted

Answered
Unable to use xlsread to open a file
for i=1:10 fil_length= xlsread(['\\some_pathway_here\Filament_Length_Dat\Filament_Length_' num2str(i) '.xls']) end

6 years ago | 0

| accepted

Answered
Forward, backward and central differences
dt=1/500; for k=1:length(Fish) Fish(k).velocity1 = gradient(Fish(k).position1,dt); Fish(k).velocity2 = gradient(Fish(...

6 years ago | 1

| accepted

Answered
How to detect the centre of four image points?
The "center" surely is the intersection of two lines passing by the two pairs of opposite circle center. So I propose you to fi...

6 years ago | 1

| accepted

Answered
What is the difference between 5 and '5'
The '5' is the char array. Char array contain a text including number, such as 'Schrodinger has 2 dogs and 1/2 cat'. Char array ...

6 years ago | 0

| accepted

Answered
Problem with Cholesky's decomposition of a positive semi-definite matrix
M=LDL’. If someone could tell me how to adapt this function to return the matrix R instead of L and D I would be extremely thank...

6 years ago | 2

Answered
Add or subtract 0.1 randomly to all elements of a matix
A + 0.1*(2*(rand(size(A))>0.5)-1) or A + 0.1*(2*(randi([0,1],size(A)))-1)

6 years ago | 1

| accepted

Load more