Answered
How do I create a set of 20 random binary numbers (only 0 and 1) but such that 0 or 1 does not repeat 4 times in a row?
a = randi([0 1],1,20); p = conv(a,[1 1 1 1],'same'); a(p == 4) = 0; a(p == 0) = 1; add a = ones(1,20); a(r...

13 years ago | 0

Answered
getting elements of a vector
g_counter = [5 6 9 0 0]; out = g_counter(g_counter == 0); or g_counter = [5 6 9 0 0]; list = [1 2 3]; ou...

13 years ago | 0

| accepted

Answered
How do I create a series of permutation matrices
a = dec2bin(0:511,9) - '0'; n = sum(a,2); out = reshape(a(n <= 6 & n >= 1,:).',3,3,[]); ADD a = dec2bin(0:511,9)...

13 years ago | 1

| accepted

Answered
indexing of an array of index
index = bsxfun(@plus,ind(:),-2:2); OR full solution index = bsxfun(@plus,min(abx(bsxfun(@minus,numdates(:),date_l(:).'...

13 years ago | 1

| accepted

Answered
finding the lowest common ancestor between 2 cells array
p1 = regexp(pc,'\.','split'); c1 = regexp(cc,'\.','split'); ii = ismember(p1,c1); k = p1(1:find(ii == 0,1,'first')-1)...

13 years ago | 0

| accepted

Answered
finding integration by using quad command
y=@(x)1./(x.^3-2*x-5); Q=quad(y,0,2); or % function in m-file: |myfun.m| function y =myfun(x), y=1./(x.^3-2*x-5)...

13 years ago | 0

Answered
Connected Neighbourhood / Regional Maxima - Image Processing
x=[ 10 10 10 10 10 10 10 10 30 30 10 13 13 10 30 10 13 10 10 10 10 10 10 10 10] imreg...

13 years ago | 0

Answered
loading and removing combined string and number vectors
A= '*0.29 *0.45 *0.37 *0.56 *0.49 *0.48 *0.45'; out = str2num(regexprep(A,'\*','')); OR out = str2double(regexp(A...

13 years ago | 0

| accepted

Answered
How to create an array using for loop?
l = A > 1; B = A; B(l) = log(B(l)); B(~l) = B(~l) + 39;

13 years ago | 0

Answered
daily averages of hourly data
a = randi(3456,52584,1); % a your hourly data out = mean(reshape(a,24,[]));

13 years ago | 1

| accepted

Answered
Error with noninteger numbers
m = bsxfun(@(x,y)8*x./abs(3*y-1) - abs(3./y.^2),.85:.05:1.2,(.5:.1:3).');

13 years ago | 1

Answered
Converting binary to decimal and vice versa, please help!!
decimal = (binarystring-'0')*pow2(size(binarystring,2)-1:-1:0).'; *ADD* binarystring = '-11.11'; b = binarystri...

13 years ago | 2

Answered
Split 132*63 by 2 or 3 for avoid complication
A = randi(125,132,63); B = A(1:2:end,1:2:end);

13 years ago | 0

Answered
want to skip the text lines in a file
f1 = fopen('test2.txt'); % your data in file test2.txt c = textscan(f1,'%s','Delimiter','\n'); fclose(f1); out = st...

13 years ago | 1

| accepted

Answered
need an empty space in a column
a = [1 4 2 5 3 2 4 0 5 6 6 1]; a(a(:,2) == 0,2) = nan;

13 years ago | 2

| accepted

Answered
creating a vector from a(:) : b(:) , but one for each index without using loops.
a=[1,2,3]; b=[6,4,9]; result = cell2mat(arrayfun(@(x,y)x:y,a,b,'un',0)); ADD a = randi(150,32,4,4,4); % your 4-D...

13 years ago | 0

| accepted

Answered
Input to Struct Array
mystruct.color = {'red', 'green', 'red', 'red'}; mystruct.angles = [30,60,90,180]; for i1=1:3 mystruct.row(i1) = ...

13 years ago | 0

Answered
How to sort a structure by numbers in one of its fields?
eg a = struct('d100',randi(125,4,5),'d458',3,'d7',rand(3),'d0','sd456'); % your data p1 = regexp(fieldnames(a),'\d*'...

13 years ago | 2

| accepted

Answered
How to transform a double loop into a single 'Cellfun' statement
s = mUnsortedNodes; [x,y] = ndgrid(1:size(s,1),1:size(s,2)); vFilter = arrayfun(@(i1,i2)strrep(strcat(s{i1,1:i2}),' ',''...

13 years ago | 0

Answered
Find Duplicates in cellarrays / use of subsindex for cellarrays
A = {'A',1;'A',2;'B',3}; [b b c] = unique(A(:,1),'first'); out1 = A(b,:); out2 = A(setdiff(1:numel(c),b),:);

13 years ago | 0

Answered
how to add extra column that counts the occurance of each character in a cellarray
GO = { 'GO:0008150' [1] [1] 'a' 'GO:0016740' [2] [2] 'b' 'GO:0006412' [2] [2] ...

13 years ago | 1

| accepted

Answered
how to delete same data
a = [ 12 0 26 94 1011 12 30 26 100 1011 1 0 26 94 1011 1 30 26 94 1011 2 0 26 95 1011 2 0 26 94 1011 2 30 26...

13 years ago | 0

| accepted

Answered
grouping binary digits from cell and convertion to a decimal value
a = reshape([out{:}],n,[])'; secret = reshape(a*pow2(size(a,2)-1:-1:0)',2,[])';

13 years ago | 1

| accepted

Answered
decimal to binary and grouping into another matrix
bi = dec2bin(secret,8) - '0'; out = reshape(mat2cell(bi,ones(size(bi,1),1),2*ones(size(bi,2)/2,1))',1,[]); or n = 8...

13 years ago | 1

| accepted

Answered
Can these operations be vectorized?
bad variant, so use loop |for .. end| s = size(Poly); n = numel(X); ii = bsxfun(@minus,ones(s(1),1)*(1:s(2)+n-1),resh...

13 years ago | 0

| accepted

Solved


Convert a numerical matrix into a cell array of strings
Given a numerical matrix, output a *cell array of string*. For example: if input = 1:3 output is {'1','2','3'} whic...

13 years ago

Answered
Finding the mean of subsets within cellarrays
[a,c,c] = unique(x(:,1)); avgx = [a,num2cell(accumarray(c,cell2mat(x(:,2)),[],@mean))];

13 years ago | 0

| accepted

Answered
creating a function to output the invert the numbers in an array
ii = numel(A):-1:1; B = A(ii); or B = A(sort(1:numel(A),'descend'));

13 years ago | 0

Answered
How to randomly select variable from the range of numbers ?
a = 1:100; ii = randperm(numel(a)); out = a(ii(1:5)); or [ii,ii] = sort(rand(1,numel(a))); out = a(ii(1:5)); ...

13 years ago | 3

Load more