Answered
sum function and add using loop
|data| - your vector with size < 31536001 x 1 >; n = numel(data); [~,t] = histc(1:n,(0:3600:n) + eps(n)); out = accum...

13 years ago | 0

Answered
How to vectorize extraction of relevant sections from multidimensional matrix?
[a1,a2,a3] = ndgrid(cw_agp,cw_tcp,cw_pcp); z = a1.*a2.*a3; s = size(V_hat); w_V_hat = V_hat.*repmat(z,[1 1 1 s(4:5)])...

13 years ago | 1

| accepted

Answered
Applying a Function to Every Element of a List
f2 = @(x,y)bsxfun(str2func(vectorize(func2str(f))),x,y.'); out = f2(1:4,2:4); % example

13 years ago | 0

Answered
find a vector in a big vector
a = randi(80,50,1); v = (2:2:20).'; [i1,i2] = ismember(a,v); i3 = find(i1); [~,jj] = sort(i2(i1)); index = i3...

13 years ago | 1

Answered
How can I repeat each element of a vector different times and store them in a new vector
r = [1 3 3 4 0 5]; x = 1:6; t = r > 0; a = cumsum(r(t)); b = zeros(1,a(end)); b(a - r(t) + 1) = 1; x1 = ...

13 years ago | 4

Answered
Generating for loop for toeplitz for Q order analysis.
b{150} = toeplitz(x,[x(1) zeros(1,150)])\y; % THAT SUCH x, y for jj = 1:150 b{jj} = b{end}(:,1:jj); end

13 years ago | 0

Answered
a simple substitution problem !
a = rand(10); a(eye(size(a))>0) = 0.5;

13 years ago | 0

Answered
eleminating data from a long vector
A=1:1000; % Example index=[10 100 500]; n = 30; A(bsxfun(@plus,index,(0:n-1)'))=[];

13 years ago | 1

Answered
Extract sub-matrices of matrix between NaN into cell array
i1 = all(~isnan(A),2); i2 = i1(:)'; idx = [strfind([~i2(1),i2],[0 1]); strfind([i2, ~i2(end)],[1 0])]; B = mat2cell(A...

13 years ago | 1

Solved


Who is the smartest MATLAB programmer?
Who is the smartest MATLAB programmer? Examples: Input x = 'Is it Obama?' Output = 'Me!' Input x = 'Who ?' Ou...

13 years ago

Solved


Determine the number of odd integers in a vector
Determine the number of unique odd integers in a vector. Examples: Input x = [2 5 8 3 7 1]; Output y = 4; Inp...

13 years ago

Solved


It's race time! Write a faster function than the test suite call of unique().
Write a function to get unique elements of a vector faster than unique()! Input will be a vector (of integers or floating point ...

13 years ago

Solved


Center of mass
Given a matrix M(m,n), where m is the number of vertices of the geometrical element and n is 2 or 3 (2D-plane figure or 3D-solid...

13 years ago

Solved


It's race time again! Write a function that is at least twice as fast as the test suite call of repmat().
Given an input element x, and the dimensions, (m, n) return a matrix of size m x n filled with element x. This must be done in l...

13 years ago

Solved


Convert elements in numeric array into different class
Write a function that converts elements in a numeric array into a different class. Example: a = [1:5]; % class: double b...

13 years ago

Solved


Create matrix of replicated elements
Given an input element x, and the dimensions, (m, n) return a matrix of size m x n filled with element x. Example: Input: ...

13 years ago

Solved


Non-zero bits in 10^n.
Given an integer that is a power of 10, find the number of non-zero bits, k, in its binary representation. For example: * ...

13 years ago

Solved


first step for Huffman Coding (easy)
Given a string, you must sort the characters by occurrence (from lowest to highest). This step is necessary to generate a Huf...

13 years ago

Answered
To remove the repeated number
% without sorting array m = randi(5,1,10); [~,ii] = sort(m); % for Jan's solution jj = [true,diff(m(...

13 years ago | 1

Answered
How to release zero elements in sparse matrix
nnz(a);

13 years ago | 0

Answered
Simulating events of varying duration
st = [23 40 67 88]; du = [3 9 2 6]; m = cumsum(du); t = m - du + 1; s = zeros(1,m(end)); s(t) = 1; ii =...

13 years ago | 1

| accepted

Solved


Generate a random matrix A of (1,-1)
Input n: is an positive integer which serves as the dimension of the matrix A; Output: A=(Aij),where each entry Aij is either...

13 years ago

Answered
interpolate using selected values of a matrix
X = [1 nan 3 4 5;6 nan 8 9 10;11 12 13 14 15]; [jj,ii] = ndgrid(1:size(X,1),1:size(X,2)); t = ~isnan(X); F = TriScatt...

13 years ago | 2

Answered
Filling the gaps in a vector
A=[nan;nan;2;nan;4;nan;nan;nan;7;nan;nan;nan;nan]; b = ~isnan(A); k = cumsum(flipud(b)); k(k==0) = 1; n = flipud(A...

13 years ago | 0

| accepted

Answered
How to extract the first and last position for each ones series ?
y = [strfind([~X(1) X],[0 1]);strfind([X ~X(end)],[1 0])]';

13 years ago | 0

| accepted

Answered
Delete a cell in an array chosen by a criterion?
years = 2002:2010; % 9 years ndy = 337 + eomday(years,2); % days in years data = cell(1,numel(years)); % ...

13 years ago | 0

Answered
How can I replace matrix with random generated number (int) and position?
eg A = [(1:20)', zeros(20,1), randi([0 20],20,1)]; for jj = 1:100 n = rand(20,1) > rand(); % B0 = rand...

13 years ago | 1

| accepted

Answered
swap matrix positions in 3d matrices
a(1,1:2,:) = a(1,[2,1],:);

13 years ago | 1

Answered
How can I generate random numbers between a range and how can I convert the output random number into binary number.
ii = [1000 4000]; % range M = randi(ii,20,1); % random numbers out = dec2bin(M,32);

13 years ago | 0

| accepted

Load more