Answered
Need help with finding distances in a matrix program
[r,c]=find(A'); dij = dist([r,c]'); % dist from Neural Network Toolbox or [r,c]=find(A'); dijx = bsxfun(@minus,r...

12 years ago | 0

| accepted

Answered
Help with compiling Matrix & Loop Function Please
a = num2cell(sub_ele_nodes,[1 2]); [aa,b] = unique(cat(1,a{:}),'first','rows'); [~,ii] = sort(b); out=aa(ii,:);

12 years ago | 0

Answered
How to remove for loops from a code
n = numel(data); S = -abs(bsxfun(@minus,data,reshape(data(candidates),1,1,[]))); S(candidates + (0:numel(candidates)-1)*...

12 years ago | 0

| accepted

Answered
how to delete the dot in a string
a = 'bbc.ed.123.f.txt'; regexprep(a,{'\.','txt'},{'','.txt'}) or [strrep(a(1:end-4),'.',''),'.txt']

12 years ago | 2

| accepted

Answered
select random number from a variable
out = a(randperm(numel(a),4)); or ii = randperm(numel(a)); out = a(ii(1:4));

12 years ago | 0

| accepted

Answered
Back track the index of a matrix
A = [ 1 3 5; 9 7 6; 2 3 4]; B = [7 4 3]; [a,b] = ismember(A,B); [r,c] = find(a); out = accumarray(b(a),1:numel...

12 years ago | 1

Answered
i want to replace cell data to index.
a = {[1 2 3 4 ] [5 6] [ 7 8 9]} ; index = [2 1 3] ; b = [10 11 12]; n = cellfun(@numel,a); v = [a{:}]; ii ...

12 years ago | 0

Answered
generating a subset of specific of unique 3 groups out of 84
C1 = real(C1); ii = nchoosek ([1:9], 3); [~,groups1] = sort(randi(100,10,9),2); % example [l,i1] = ismember(sort(...

12 years ago | 0

Answered
matrix 9x9 with duplicate values
function test1 A = randi(15,3) B=A; B(tril(B)>0)=nan; C=B(~isnan(B)); [a,b] = unique...

12 years ago | 0

Answered
How to combine random size arrays in one matrix - in a loop?
for jj = 1:10 v = randi(randi(234),randi(12),1); if jj==1 out = v; else n = [size(o...

12 years ago | 0

Answered
How to shift rows in a matrix by different values (e.g. line 1 n-spots, line 2 m-spots and so on) without using a loop
r = rem(random,10); c = [cycle,cycle]; out = c(bsxfun(@plus,bsxfun(@plus,10 - r,0:9)*5,(1:5)'));

12 years ago | 2

| accepted

Answered
Subract specific areas from array
[a,b] = regexp(num2str(A(:))','(?<=1)2*(?=1)'); t = false(size(A)); for jj = 1:numel(a) t(a(jj):b(jj)) = true; ...

12 years ago | 0

Answered
Rearrange 3 small matrices to a bigger one with a certain order: taking first n-rows of each of the smaller matrices after each other
a1 = cat(1,A1,A2,A3); t = rem(0:size(a1,1)-1,4)+1 <= 2; out = [a1(t,:);a1(~t,:)]; or in one row out = reshape(pe...

12 years ago | 1

Answered
Insert Zeros (m -rows) in an existing Matrix every n-rows in an efficient way
m = 3; k = 2; n = size(A); out = reshape([reshape(A,m,[]);zeros(k,n(1)/m*n(2))],[],n(2)); or m = 3; k = ...

12 years ago | 1

Answered
How to read digits from file to matrix, no delimeter
f = fopen('pathyourtextfile.txt'); c = textscan(f,'%s','delimiter','\n'); fclose(f); out=cat(1,c{:}{:});

12 years ago | 0

Answered
assigning text from values
t = {'yes', 'no', 'maybe', 'abstain'}; X = [0,2,3,2,1,3,2,1,0]; out = [num2cell(X);t(X+1)];

12 years ago | 0

| accepted

Answered
Help with creation/alteration of a tri-diagonal matrix, using loops/ alternatives...
m = numel(h); h = h(:); d2 = delta.^2; A = conv2(h,[1/4;1;-1/4],'valid')/d2; B = 2*h(2:end-1)/d2; C = conv2(h,[...

12 years ago | 0

Answered
how to convert arrays inside my cell array into cells?
out = num2cell(cities)

12 years ago | 0

| accepted

Answered
transform a vector to a cell array
d = num2cell(c(hankel(1:3,3:numel(c))),2)

12 years ago | 0

Answered
Using logical operators within if statement
while true um=input('um(Between 0 and 1) ='); if um<0 || um>1 disp('Enter a valid value'); els...

12 years ago | 1

Answered
Breaking up a long variable into more rows and less columns
out = reshape(1:18144,126,[])';

12 years ago | 0

| accepted

Answered
Transform matrix in vectors in a cell array
num2cell(reshape([c{:}],4,[]),2)

12 years ago | 0

Answered
How do I create such matrix ? (please look at the thread for further details)
X = randi(25,1,10); n = 3; X = X(:); X = [X(1:n);conv2(X(1:end-n+2),ones(n,1)/n,'valid')]; on Deric's comment ...

12 years ago | 0

Answered
How can I find the values for three parameters, (a, b, c), using a minimum sum of squares criterion?
Example to answer Walter: yfun = @(x,c)c(1)*x.^c(2).*(1-x).^c(3); lny = log(y); c1 = [ones(size(lny)),log(x),...

12 years ago | 0

Answered
Error using ==> vertcat CAT arguments dimensions are not consistent.
Please try this code: r1 = (1:.26:5.2)'; r2 = (1:17)'; [i1,i2] = ndgrid(r1,r2); g=((i2+i1).^3-i1.^3)./(i2+i1).^3; ...

12 years ago | 1

| accepted

Answered
Insertion of the index
n =4; k = [3,2,4,6]; i1 = repmat((1:n)',1,n); p = i1.*~eye(n)+triu(ones(n)); i3 = rem(bsxfun(@plus,reshape(0:n-1...

12 years ago | 0

Solved


Narcissistic number ?
Inspired by Problem 2056 created by Ted. In recreational number theory, a narcissistic number is a number that is the sum of ...

12 years ago

Answered
Sort columns by maximum value?
with |subsref| y = x(:,subsref(sortrows([max(x)',(1:size(x,2))'],1),struct('type','()','subs',{{':',2}})))

12 years ago | 0

Answered
Create new smaller Matrix by summing every n-rows in old Matrix (without loops)
s1 = size(A); s2 = [3 3]; % size of the matrix- result ii = rem((1:s1(1))'-1,s2(1))+1; [i1,i2] = ndgrid(ii,1:s1(2)); ...

12 years ago | 0

| accepted

Answered
How to quickly change 3D to 2D Matrix
B = reshape(permute(A,[2 1 3]),size(A,2),[])'; or p = num2cell(A,[1 2]); B = cat(1,p{:});

12 years ago | 0

| accepted

Load more