Answered

How to split a row vector into sub vectors with different sizes?

h = [1 2 3 4 5 6 7 8 9 10 11]; n = [3, 3, 2, 2]; m = mat2cell(h(2:end),1,n)

How to split a row vector into sub vectors with different sizes?

h = [1 2 3 4 5 6 7 8 9 10 11]; n = [3, 3, 2, 2]; m = mat2cell(h(2:end),1,n)

2 days ago | 1

| accepted

Answered

How many times does a pair of value occur in a row?

a = nchoosek(1:4,2); d0 = repelem(dat',2,1); d0 = d0(2:end-1,:); out = squeeze(sum(all(sort(reshape(d0,2,[],2)) == reshape(a'...

How many times does a pair of value occur in a row?

a = nchoosek(1:4,2); d0 = repelem(dat',2,1); d0 = d0(2:end-1,:); out = squeeze(sum(all(sort(reshape(d0,2,[],2)) == reshape(a'...

2 days ago | 1

Answered

accumarray function for equal integer values

B1 = [34.1; 34.2; 35.6; 35.7]; B2 = [600; 800; 200; 100]; B = table(B1,B2); B.B1 = round(B.B1); Bnew = varfun(@sum,B,'Grou...

accumarray function for equal integer values

B1 = [34.1; 34.2; 35.6; 35.7]; B2 = [600; 800; 200; 100]; B = table(B1,B2); B.B1 = round(B.B1); Bnew = varfun(@sum,B,'Grou...

2 days ago | 1

Answered

find matching values from two unequal size arrays

Let: a = [lat1 lon1 pCO2]; b = [lat2 lon2]; b(:,3) = a(ismember(a(:,1:2),b,'rows'),3);

find matching values from two unequal size arrays

Let: a = [lat1 lon1 pCO2]; b = [lat2 lon2]; b(:,3) = a(ismember(a(:,1:2),b,'rows'),3);

7 days ago | 0

Answered

how do I create this loop?

zrs = zeros(size(TT,1),1); TT.G = zrs; TT.SG = zrs;

how do I create this loop?

zrs = zeros(size(TT,1),1); TT.G = zrs; TT.SG = zrs;

18 days ago | 0

Answered

cut x and y array on datetime

lo = x(x <= specific_date); y_out = y(lo);

cut x and y array on datetime

lo = x(x <= specific_date); y_out = y(lo);

18 days ago | 0

| accepted

Answered

Replace groups of numbers in a matrix checking connections in 8-directions

<https://www.mathworks.com/matlabcentral/answers/425576-replace-numbers-in-a-matrix-depending-on-the-shape-in-which-a-group-of-n...

Replace groups of numbers in a matrix checking connections in 8-directions

<https://www.mathworks.com/matlabcentral/answers/425576-replace-numbers-in-a-matrix-depending-on-the-shape-in-which-a-group-of-n...

18 days ago | 1

Answered

Assign Field to Structure Array without a Loop

cellarray = num2cell([Field1(:),Field2(:)]); namefields = {'Field1','Field2'}; StructArray = cell2struct(cellarray,n...

Assign Field to Structure Array without a Loop

cellarray = num2cell([Field1(:),Field2(:)]); namefields = {'Field1','Field2'}; StructArray = cell2struct(cellarray,n...

23 days ago | 1

Answered

How to transpose values of arrays between matrices

z = z(:)'; zz = z(59472:59555); out = zz(Indices);

How to transpose values of arrays between matrices

z = z(:)'; zz = z(59472:59555); out = zz(Indices);

24 days ago | 0

| accepted

Answered

Replace numbers in a matrix depending on the shape in which a group of numbers are located

out = 2 - A; cc = bwconncomp(out); z = cc.PixelIdxList; n = cellfun(@numel,z) >= 3; idx = z(n); zz = cellfun(@(...

Replace numbers in a matrix depending on the shape in which a group of numbers are located

out = 2 - A; cc = bwconncomp(out); z = cc.PixelIdxList; n = cellfun(@numel,z) >= 3; idx = z(n); zz = cellfun(@(...

24 days ago | 1

| accepted

Answered

How to multiply all values in the diagonal of a matrix by -1 in Matlab?

max(a21(:),a21(:)').^2 .* (ones(5) - 2*eye(5));

How to multiply all values in the diagonal of a matrix by -1 in Matlab?

max(a21(:),a21(:)').^2 .* (ones(5) - 2*eye(5));

24 days ago | 0

Answered

How to build a matrix of 0, 1 and 2 according to the answers made by individuals of a survey

ABC = [3,8 11,15 9,9]; s = size(ABC); [ii,~] = ndgrid(1:s(1),1:s(2)); out = accumarray([ii(:)...

How to build a matrix of 0, 1 and 2 according to the answers made by individuals of a survey

ABC = [3,8 11,15 9,9]; s = size(ABC); [ii,~] = ndgrid(1:s(1),1:s(2)); out = accumarray([ii(:)...

24 days ago | 1

| accepted

Answered

select part vector put it back in other vector

S(S./movmean(S,31) >= 3) = NaN;

select part vector put it back in other vector

S(S./movmean(S,31) >= 3) = NaN;

24 days ago | 0

Answered

how to formulate logical matrix in a loop?

A = 1:10; idx = A(:) == A(:)'

how to formulate logical matrix in a loop?

A = 1:10; idx = A(:) == A(:)'

24 days ago | 1

| accepted

Answered

Concatenate rows of cell into one column

C = cellfun(@cell2mat,num2cell(A,2),'un',0);

Concatenate rows of cell into one column

C = cellfun(@cell2mat,num2cell(A,2),'un',0);

25 days ago | 0

| accepted

Answered

Creating array by picking certain elements from another array

s = size(A); [ii,jj,~] = ndgrid(1:s(1),1:s(2),1:s(3)); ij = [ii(:),jj(:),A(:),B(:)]; ij = ij(~isnan(ij(:,3)),:); o...

Creating array by picking certain elements from another array

s = size(A); [ii,jj,~] = ndgrid(1:s(1),1:s(2),1:s(3)); ij = [ii(:),jj(:),A(:),B(:)]; ij = ij(~isnan(ij(:,3)),:); o...

26 days ago | 0

Answered

How to convert cells within cells to double.

Let A - your cell array with cells out = cell2mat(cellfun(@cell2mat,A,'un',0));

How to convert cells within cells to double.

Let A - your cell array with cells out = cell2mat(cellfun(@cell2mat,A,'un',0));

26 days ago | 0

Answered

Why does it give an error of "Array indices must be positive integers or logical values."

k1=0.005; Cao= 31.553; K1=0.0012; K2=0.0025; k2=0.003; x = [k1 Cao K1 K2 k2]; tspan= [1 500]; y0= [14...

Why does it give an error of "Array indices must be positive integers or logical values."

k1=0.005; Cao= 31.553; K1=0.0012; K2=0.0025; k2=0.003; x = [k1 Cao K1 K2 k2]; tspan= [1 500]; y0= [14...

26 days ago | 0

Answered

Please how can I convert the some values of my cell array from 0 to NaN

A - your cell array. for ii = 1:numel(A) A{ii}(A{ii} == 0) = nan; end

Please how can I convert the some values of my cell array from 0 to NaN

A - your cell array. for ii = 1:numel(A) A{ii}(A{ii} == 0) = nan; end

27 days ago | 1

Answered

accessing all elements along the diagonals and rows (simple backprojection algorithm for image reconstruction)

A = [1 4 7 10 13; 2 5 8 11 14; 3 6 9 12 15]; s = size(A); n = ones(s(1),1); a = n*sum(A)/s(1); b...

accessing all elements along the diagonals and rows (simple backprojection algorithm for image reconstruction)

A = [1 4 7 10 13; 2 5 8 11 14; 3 6 9 12 15]; s = size(A); n = ones(s(1),1); a = n*sum(A)/s(1); b...

30 days ago | 0

Answered

Generation of a matrix based on a defined order of numbers

v1 = [2 3 4 5 6 7 8 9]; v2 = [3 4 5 6 7]; n = numel(v2); q = nchoosek(v1,2)'; m = reshape(permute(... ...

Generation of a matrix based on a defined order of numbers

v1 = [2 3 4 5 6 7 8 9]; v2 = [3 4 5 6 7]; n = numel(v2); q = nchoosek(v1,2)'; m = reshape(permute(... ...

1 month ago | 1

Answered

find unique sets of values in matrix, eliminate duplications

r = [3;5;6]; B = A(r,:)'; [~,~,c] = unique(B(:,2:3),'rows','stable'); ii = find(histcounts(c,1:max(c)+1) > 1); ...

find unique sets of values in matrix, eliminate duplications

r = [3;5;6]; B = A(r,:)'; [~,~,c] = unique(B(:,2:3),'rows','stable'); ii = find(histcounts(c,1:max(c)+1) > 1); ...

1 month ago | 1

| accepted

Answered

Sorting data from table

T - your table with variables: month, day, year and prutok. ii = findgroups(T.year); Prutok = accumarray(ii,T.prutok,[],...

Sorting data from table

T - your table with variables: month, day, year and prutok. ii = findgroups(T.year); Prutok = accumarray(ii,T.prutok,[],...

1 month ago | 0

| accepted

Answered

Transform column data to m x n matrix

OriginalData = readtable('Path_to_your_file\DataTransformation.xlsx',... 'Range','A3:C26',... 'ReadVariableNames',true);...

Transform column data to m x n matrix

OriginalData = readtable('Path_to_your_file\DataTransformation.xlsx',... 'Range','A3:C26',... 'ReadVariableNames',true);...

1 month ago | 1

| accepted

Answered

How can i sum over seconds ?

T = testclick; T.Noisedb0061 = datetime(T.Noisedb0061,'I','uuuu-MM-dd hh:mm:ss.SSS'); TT = table2timetable(T(:,2:end),'R...

How can i sum over seconds ?

T = testclick; T.Noisedb0061 = datetime(T.Noisedb0061,'I','uuuu-MM-dd hh:mm:ss.SSS'); TT = table2timetable(T(:,2:end),'R...

1 month ago | 1

Answered

Correspondance matrix for matching values in two vectors

a = [2 2 2 2 2 1 1 1 3 3 2 2 1 1 1 1 3 3 2 2]; b = [1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1]; [a1,~,c] = unique(a); ...

Correspondance matrix for matching values in two vectors

a = [2 2 2 2 2 1 1 1 3 3 2 2 1 1 1 1 3 3 2 2]; b = [1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1]; [a1,~,c] = unique(a); ...

1 month ago | 0

Answered

How do i convert randint function to randi function using Matlab

b=randi([0,1],1,n);

How do i convert randint function to randi function using Matlab

b=randi([0,1],1,n);

1 month ago | 0