Answered
NxN matrix with 2s on main diagonal
toeplitz([2 -1 zeros(1,n-3) -1])

9 years ago | 0

Answered
create a matrix from a matrix x=[-2 -1 0 1 2]; which follow quadratic equations
x = [-2 -1 0 1 2]; out = x(:).^(2:-1:0); % for R2016b

9 years ago | 0

Answered
Create copies of each row of an array
kron(A,[1;1]) or repelem(A,2,1)

9 years ago | 1

| accepted

Answered
How do I split double-digit elements in a vector into two separate elements?
v = [1 18 9 8]; new_vec = sprintf('%d',v)-'0';

9 years ago | 2

Answered
Insert "1" at specific ranges in a matrix
z =repmat({ones(1,9)},40,1); out = blkdiag(z{:}); or out = kron(eye(40),ones(1,9));

9 years ago | 1

Answered
Top N values for multidimensional matrix with different N at each grid cell
Let |A| and |B|: A= [0 1 5 10 12 12 3 4 8 9 4 6 8 9 0] B = randi([3 8],3,5,15); solution: t = A > ...

9 years ago | 0

| accepted

Answered
Insert cell array objects into a pre-made array
Bc = num2cell(B); t = B ~= 0; C = A; C(t) = Bc(t);

9 years ago | 0

Answered
Replacing small sections of a logical vector
v = bwlabel(EMG); EMG(ismember(v,find(accumarray(v(:)+1,1)<=3)-1)) = 0;

9 years ago | 0

Answered
How do I get the mean of a row in a matrix?
rmA = mean(A,2); rmB = mean(B,2);

9 years ago | 1

| accepted

Answered
loop for matlab array
c = (a(:)*2 - 1)*b(:)'; or c = (a(:)*2 - 1).*b(:);

9 years ago | 0

Answered
really need help on this question!!!! I want to calculate the sum of all odd number, where do I do wrong?
A=[12 2 33 15 66; 40 54 79 14 14; 88 2 54 30 47; 37 85 92 14 48; 55 19 88 62 37; ...

9 years ago | 1

| accepted

Answered
Please help!!!! Write a function that returns the number of days between dates
days_between_dates = @(month1,day1,year1,month2,day2,year2)... abs(datenum(year1,month1,day1) - da...

9 years ago | 0

| accepted

Answered
mean of all positives in a cell array
m1 =cellfun(@(x) [mean(x(x<0)),mean(x(x>0))],s,'un',0)

9 years ago | 0

| accepted

Answered
How can I generate a matrix as in the picture?
n = 6; % Let n = 6 z = [-1 3 -3 1]; m = numel(z); k = n-m+1; A = full(spdiags(ones(k,1)*z,0:m-1,k,n)); othe...

9 years ago | 0

| accepted

Answered
Interpolation of hourly data into minutes
here |a| - your hourly values. out = kron(a,ones(60,1)/60)

9 years ago | 1

| accepted

Answered
how can I choose the positive one between the numbers
Let here |a| - your roots (negative and positive) a_positive = a(a > 0);

9 years ago | 0

Answered
Generating an "all-combinations" matrix for a given vector
A = fullfact(x(end:-1:1)); A = flip(A,2)'; other way :) x = [2 3 4]'; k = arrayfun(@(ii)1:ii,x(end:-1:1),'un',0)...

9 years ago | 1

Answered
sum even and odd places values
B = sum(A(2:2:end)); C = sum(A(1:2:end));

9 years ago | 3

Answered
How to apply a multivariate function to each element of a vector?
>> a=1; b=2; c=3; X=-10:10 X = -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6...

9 years ago | 0

Answered
Index information for conv2(.,.)
Without |Image Processing ...| m = 3; n = 5; A = reshape(1:numel(X),size(X)); [k,l] = size(A); s = floor([m,n]/...

9 years ago | 0

Answered
I have two for loop which generate as result a vector. Every time I get a vector I want to store it inside a matrix. So, this finial matrix will have every index being a vector. I can't find a way to do it.
example for users of R2016b and Octave C = linspace(5,20,10).'; % [MPa] alpha = linspace(0.300,0.500,10); x = reshap...

9 years ago | 0

Answered
function using X=@x[1,x,x^2,...x^n] of length x.
X = @(x)x(:)'.^(0:2)'; % R2016b X = @(x)bsxfun(@power,x(:)',(0:2)');% R2016a and earlier

9 years ago | 1

Answered
how to sum value of fields on struct?
z = struct2cell(s(:)); out = sum(reshape([z{:}],size(z)),2); or general variant z = cellfun(@(x)x(:)',struct2cell(s...

9 years ago | 3

Answered
how can i get a number from a string.
str = 'index_N=10'; out = str2double(regexp(str,'\d*','match'));

9 years ago | 1

Answered
conversion of daily cell into monthly cell.
[Y,M] = datevec([day_wise_wind_chembur{:,2}]'); [a,~,c] = unique([Y,M],'rows'); out = [num2cell(a,2),... ac...

9 years ago | 0

| accepted

Answered
How to select two matrices randomly from a set of N matrices and then randomly select a few rows from first selected matrix and then exchange with corresponding rows of other selected matrix.
For the case where the matrices have the same size: Q = cat(3,A,B,C,D,E,F,G,H,I,J); ii = [3,8] % C and H n = size(Q,1...

9 years ago | 0

Answered
want to make a number of row matrix from a single row matrix
Let |A| - your matrix (2 x 9) A = reshape(1:18,[],2)'; out = reshape(A,2,3,[]);

9 years ago | 0

Answered
How to do crossover between two matrices.
ii = [1,3] E = cat(3,A,B); E(ii,:,:) = E(ii,:,end:-1:1); CC = num2cell(E,[1,2]); [C,D] = CC{:};

9 years ago | 0

| accepted

Load more