Answered
vectorizing a script with cellfun
data = arrayfyn(@(ii)cellfun(@(x)dlmread(fullfile(main_folder,Name1{ii},x)),FilesToRead{ii},'un',0),1:length(FilesToRead),'un'...

14 years ago | 1

| accepted

Answered
Number of ones
out = sum(BW,2)

14 years ago | 0

Answered
how to change the value of a group of number
a = 1:15 out = rem(a-1,5)+1

14 years ago | 0

| accepted

Answered
Ordering rows based on value
k1 = bsxfun(@minus,matches(:,1),matches(:,2)'); [ii,jj] = find(k1 == 0); a = unique([ii;jj]); out1 = unique(matches(a...

14 years ago | 0

| accepted

Answered
How do I create a vector with a multiply sequence?
vector = [1 cumprod(ones(1,9)*.7)]*100; more variant o10 = ones(10); vector = 100*prod(o10 - .3*triu(o10,1));

14 years ago | 1

Answered
finding distance between centroids
try D = dist([X,Y]')

14 years ago | 1

Answered
Problem with imwrite
try fullfile(cd, strcat('Results\',num2str(x(i)),'.jpg'))

14 years ago | 0

| accepted

Answered
Mapping
bidata = [0 0; 0 1; 1 0; 1 1] out = bidata*[4;2] - 3 *ADD* inverse problem bidata = floor(rem(bsxfun(@rdivide,(data...

14 years ago | 0

Answered
cells related
variant numcell = randperm(numel(Vn),4); rows1 = 1:4; datarnd = arrayfun(@(x,y)Vn{x}(y,:),numcell,rows1,'un',0); o...

14 years ago | 0

| accepted

Answered
Matrix
eg S1 = randi([-1 1],10) S2 = randi([-1 1],10) solution k= S1 + S2 S = (k==2) - (k==-2) OR S = (S1 ==...

14 years ago | 0

| accepted

Answered
convert a logical matrix to the numeric one
in your case B2 = B*5 + 5 OR k = [5 10] B2 = k(B + 1)

14 years ago | 1

Answered
finding black pixel position
[ii,jj] = find(all(I==0,3)) [~,k] = unique(ii,'first') ij = [ii(k) jj(k)]

14 years ago | 1

| accepted

Answered
calculate divergence
so? a=r.*exp(-(r./2).^2);

14 years ago | 0

Answered
distance
use |.^| d1=sqrt(((xi(:,1)-c1))^2+(yi(:,1)-c2)^2); d11=sqrt(((xi(:,2)-c1)).^2+(yi(:,2)-c2).^2); on comment d = s...

14 years ago | 1

Answered
str2num conversion for vectors
A = str2num('uint16([500 300 100])')

14 years ago | 0

| accepted

Answered
How to change an if-condition in a loop by logical indexing to make my code faster?
[EDIT] try fn = fieldnames(A); for jj = 1:numel(fn) n = fn{jj}; [a b] = ismember(A.(n),B.(n),'rows'); C...

14 years ago | 0

Answered
Saving integer as a bit
in your case use |logical| array a1 = randi([0 1],10)); a2 = logical(a1);

14 years ago | 0

Answered
removing inner for loop
sum1 = sum(bsxfun(@times,a,reshape(pr,1,1,[])),3) OR in this is case b = unique(pr); k = histc(pr(:),b); sum1...

14 years ago | 1

| accepted

Answered
cell comparison with other cells in different rows
*[EDIT]* :) ep = {{-24.7697910000000,-15.8191235000000},{-20.6771670000000,-3.54125200000000}; {-12.6771670000000,20...

14 years ago | 0

Answered
summing tied (duplicate) numbers in a series
t = [4 4 6 7 9 9 9 10 10 13 17 17 17] [a n n] = unique(t) m = histc(n,1:max(n)) tout = accumarray(m',a',[],@(x){x})

14 years ago | 0

Answered
connected components pixels
STATS = regionprops(logical(BW),'PixelIdxList')

14 years ago | 0

Answered
Matrix Standard Deviation in 3D neighborhood
% I - your 3D matrix - array(NxNxM) k = padarray(I,[1 1],'symmetric'); s = size(I); out = zeros(s(1),s(2)); for j1...

14 years ago | 0

| accepted

Answered
call a function with the namefunction in a variable
|doc feval| |doc eval| eg a = 'size'; [s1 s2] = feval(a,[1 2 3])

14 years ago | 2

| accepted

Answered
Finding 3 consecutive zero values row by row in an image.
x1 = all(img==0,3); rst = conv2(x1+0,[1 1 1],'same'); [ii,jj] = find(rst == 3); jj = bsxfun(@plus,jj,-1:1);

14 years ago | 1

Answered
how to set elements in a matrix to infinite
A = A +0; A(~eye(size(A))&A == 0) = inf

14 years ago | 0

| accepted

Answered
simple for loop problem
lowlim=max(hd)-mean(hd); t = hd<lowlim; t2 = find([true;diff(t)~=0]); id = t2(bsxfun(@plus,find(t(t2)),[0 1])); id...

14 years ago | 0

| accepted

Answered
Find the longest word in a character vector
phstr = 'etetetettete fhfhfh fg fgfgf tdfhfjfkfkfk nfjfiekehdfjgjgugtltrj' wcl = regexp(phstr,'\w*','match') [~,ii] = ma...

14 years ago | 0

Answered
sorting and counting
a = [ 1 2 5 7] ; b = [ 9 9 3 4] ; [aa bb] = ndgrid(a,b); k = [aa(:) bb(:)]; [n1, n2, n2] = unique(k,'rows'); n3 = ...

14 years ago | 1

| accepted

Load more