Answered
What frustrates you about MATLAB? #2
FIND(..., 0) throw an error. >> x=rand(1,10)>0.6 x = 1×10 logical array 1 0 1 1 1 0 0 0 1 1 ...

6 years ago | 3

Answered
The shortest way to find the sequence of all 1s to all 0s
Build full Graph and select the shortest path N = 12; % number of bits D = 9; % number of flips for each step, <= N E0 = (...

6 years ago | 1

| accepted

Answered
K-th order neighbors in graph
It sounds like you look at graph-distance and NOT what you described "K-th order neighbors are defined as all nodes which can be...

6 years ago | 2

Answered
The shortest way to find the sequence of all 1s to all 0s
For the shortest, you would probably want to take a look of dynamic programming. A standard problem quite similar to yours is t...

6 years ago | 0

Answered
How can one do this calculation?
assuming your grid is 1:5 x 1:5, so A is (25 x 3). Example of fake data i=1:5 i = 1 2 3 4 5 j=1:5...

6 years ago | 0

Answered
K-th order neighbors in graph
Assuming A is the transposed of the adjacent matrix (n x n). j in (1:n) is the source node number. This method should be fast...

6 years ago | 0

Answered
What frustrates you about MATLAB? #2
If would be greak MATLAB can do auto-expansion-like for array concatenation >> A=1:4 A = 1 2 3 4 >> B...

6 years ago | 2

Answered
Permutation and combination to flip the numbers in the array
A = logical([1 0 1 0 1 1]) nflip = 2; m = size(A, 2); j = nchoosek(1:m, nflip); i = repmat((1:size(j,1))', [1,size(j,2)]);...

6 years ago | 0

| accepted

Answered
Combination of rows of two different matrices
A = [-0.6, -0.2; -60, 2; 6, -20]; B = [-0.4, -0.8; -40, 8; 4, -80]; Single statement ...

6 years ago | 2

Answered
delete zeros from matrix
Here is how using FOR-LOOP to delete zero column(s) A = [0 0 31 37 43 47; 0 0 19 13 7 3...

6 years ago | 1

| accepted

Answered
Permutation and combination to flip the numbers in the array
If I understand the question correctly A0=[1 0 1 0 1 1] % A1 is all possible single swap (permutation of 2 elements) of % b...

6 years ago | 0

Answered
From a matrix, Pick one element from each row and not from same column for all possibilities. Only for non zero elements.
A dynamic programming for fun function p = nzperm(A,c) if nargin < 2 c = 1; end r = find(A(:,c)); if isempty(r) ...

6 years ago | 0

Answered
Index not working - very simple problem!
Your 3 in array is actually not 3 but something like 3.0000000001 or other variant. When you see MATLAB dispay with .0000 if of...

6 years ago | 0

Answered
How to write pentadigonal matix?
Is it good now? n = 12; m = ceil(n / 3); n = m*3; A = spdiags([1 -4 1]+zeros(3,1), -1:1, 3, 3); c = repmat({A},1,m); A =...

6 years ago | 0

| accepted

Answered
random selection of a cell
A = zeros(100,100); something = 1; for c = 1:100 r = randi(97) + (0:3); A(r,c) = something; end

6 years ago | 0

Answered
How to plot circular arc passes through 3 points ?
Assuming you have angle vector in radian. Change anglevectorCCW = linspace(angle1, angle2) to anglevectorCW = linspace(min(an...

6 years ago | 0

Answered
How to generate random uniform disturbed random vectors of euclidian lenght of one?
My conjecture: the only dimension that is possible of generate uniform distribution for all components is n==3 (n is nvars in th...

6 years ago | 1

| accepted

Answered
What is the fastest way to compute the frequency of occurrence in a matrix?
M = [1 2 3; 4 5 6; 1 2 3; 7 8 9; 7 8 9; 7 8 9; 9 9 9; 9 9 9; 9 9 9] [~,~,J] = unique(M,'rows'); n = accumarray(accumarray(J,...

6 years ago | 0

Answered
Find all possible unique combinations of weights of 3 assets
n=3; s=100; a = nchoosek(1:s+n-1,n-1); z = zeros(size(a,1),1); w = diff([z,a,s+n+z],1,2)-1

6 years ago | 1

Answered
How to find out zeros and their indices in a matrix?
v=input(2,:)>0; % remove >0 if your matrix contains only 0 or 1 d = diff([1, v, 1]); index = find(d==-1) output = find(d==1...

6 years ago | 2

| accepted

Answered
how to make random vector with a certain profile
Modified code in case r is not equidistance (but monotonic) rmid = 0.5*(r(1:end-1) + r(2:end)); dr = r(2:end)-r(1:end-1); fvf...

6 years ago | 0

Answered
how to make random vector with a certain profile
r=linspace(0,1.5); fv=(1.5-r).*(2+10*exp(-((r-1)./0.3).^2)); % whatever unnormaized pdf % NOTE: This method assumes r is an ...

6 years ago | 0

Answered
make a vector from one value
One way (among many) x = 0.421 + zeros(1,1200)

6 years ago | 0

| accepted

Answered
Is this a new bug?
Numerical inaccuracy limitation. Nothing new in this front and no one consider them as BUG. Sometime symmetrize the matrix help...

6 years ago | 0

Answered
Is it possible to accelerate the speed of saving data into files with parallel way?
You might try to remove the for-loop fp = fopen(filename,'w'); fprintf(fp,'%d %d %d %d\n', a(:,1:4).'); % remove the indexing ...

6 years ago | 0

| accepted

Answered
How to 'unfold' or 'reverse groupcounts?
c = [1 2; 2 1; 3 3; 4 1] repelem(c(:,1).',c(:,2).')

6 years ago | 0

Answered
For loop with string comparison
Change to ... if strcmp(S(i).Status,'Active') || strcmp(S(i).type,'N') ... end

6 years ago | 0

| accepted

Answered
How to create an empty array of structs?
Been there, done that. The most generic way I deal with such situation is like that using a function CATSTRUCT I have created (a...

6 years ago | 0

Answered
Does Matlab Compiler fully support multi-window apps?
Yes No.

6 years ago | 0

| accepted

Load more