Answered
Averaging the previous 5 values of every 30 values in a matrix
m = size(numData,1); lo = mod((0:m-1)',30) + 1 >= 26; ii = ceil((1:m)'/10); HRmean5 = accumarray(ii(lo),numData(lo,3),[],@mea...

6 years ago | 0

Answered
Generate a N length vector from a M length list (permutation)
out = fullfact(3*ones(1,5));

6 years ago | 0

Answered
Find rows in matrix based on columns value
My case for mat: mat = [1 11 3 10 5 6 10 10 9 10 11 12]; mat2 = sort(mat,2); [m,n...

6 years ago | 2

Answered
Sum if multiple conditions satisfied across vectors
MKT = [1 ; 1 ; 1 ; 2 ; 2 ; 2]; GROUP = [1 ; 1 ; 2 ; 1 ; 2 ; 2]; SHARE = [0.2 ; 0.3 ; 0.5 ; 0.6 ; 0.1 ; 0.3]; T = table(MK...

6 years ago | 0

| accepted

Answered
Replace row of matrix with vector by logical indexing
a = 101:120; lo = a(:) > 112; b(lo,:) = lo(lo>0).*[55,56,57,58,59];

6 years ago | 0

Answered
How to find unique combinations between two columns in a cell array
test = {'sensor1', 'sensor1', 'sensor2', 'sensor2', 'sensor3', 'sensor3'; '99' '99' '98' '97' '98' '97'}' T = cell2table(t...

6 years ago | 0

| accepted

Answered
how to Expanand any matrix
out = cell2mat(arrayfun(@(x,y)diag(ones(5-x,1),x)*y ,abs(a),a>=0,'un',0)); or z = cell(size(a)); k = zeros(5); for ii = 1:nu...

6 years ago | 0

Answered
recode the missing values equal to the preceding recorded value
lo = anuual_CO2(:,2) ~= -999; x = anuual_CO2(lo,2); anuual_CO2(:,2) = x(cumsum(lo));

6 years ago | 0

Answered
add new rows to a Matrix
A = rand(11,6); out = addedNansRows(A,3,4) Here addedNansRows: function out = addedNansRows(A,m,n) % A - array % m -...

6 years ago | 2

| accepted

Answered
How to call a specific element of a table
load data.mat lo = ismembertol(T{:,{'time','perhexagon'}},[2,2.1667],'ByRows',true,... ...

6 years ago | 0

Answered
Infinite for loop getting stuck. Creating a new column containing a variable.
kk = [data.NAPMPMIIndex > 50, data.AboveMA > .5]; g = findgroups(kk(:,1),kk(:,2)); a = [-1;1;-.5;.5]; data.signal = a(g);

6 years ago | 2

| accepted

Answered
How can I code so: if a value on an array is false(0), and there is another false later on the list,all the 1's between (true) all the 1's turn into 0?
A = [0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0]; imerode(imdilate(A,[1 1 1]),[1 1 1]); or c = cumsum(A); cc = cumsum(A,'re...

6 years ago | 0

Answered
Efficiently add cell value from a matrix row based on corresponding index to another matrix row
m = size(B,1); C = reshape(B,m,2,[]); C(:,end+1,:) = reshape(A(B(:,2:2:end),4),m,1,[]); C = reshape(C,m,[]); or m = size(B,...

6 years ago | 0

| accepted

Answered
How select a first value from the binary matrix ?
out = cumsum(cumsum(matrix)) == 1; or out = cumsum(matrix) == 1 & matrix;

6 years ago | 1

| accepted

Answered
How can I compare a set of variables?
x= [1; 3; 4; 3; 3; 1; 2] [~,~,c] = unique(x,'stable'); x_out = accumarray(c,x,[],@(x){x});

6 years ago | 1

Answered
Sorting Table Data by Groups of Rows
Let T - your table with size (176120x5) and T(:,1) - the timestamp column. T{:,1} = fillmissing(T{:,1},'previous'); T_out = so...

6 years ago | 0

Answered
How to change non zero value into 0?
Let A - your binary array (n x n) m = 10; B = cumsum(A); out = A.*(B(end,:) - m >= B);

6 years ago | 3

| accepted

Answered
Find Number of Elements in an Array
A = {'KM'; 'KL'; 'MN'; 'KM'; 'MM'; 'KL'}; out = varfun(@x,table(A),'GroupingVariables','A')

6 years ago | 0

Answered
Splitting one column into multiple columns
input = {'0.17 1.7285 0.001763792 1.000977 56651.41 0.000017652 DHT11, OK, 35.0,'; ...

6 years ago | 1

Answered
Resample datetime to minute resolution
T = fuel1(:,{'Start','Volume'}); T.Properties.VariableNames={'time','vol'}; T1=table; T1.time = fuel1.End; T1.vol = zeros(si...

6 years ago | 1

| accepted

Answered
How to organize a table?
T = readtable('img1.txt'); out = varfun(@sum,T,'GroupingVariables',... {'time','cell_type'},'InputVariables','cell_t...

6 years ago | 0

Answered
work with matrix of words and number
T = readtable('txtfile.txt') T_out = varfun(@mean,T,'GroupingVariables','Var1');

6 years ago | 0

| accepted

Answered
To generate alternate 0's and 1's
out = repelem(mod(0:numel(A)-1,2),A);

6 years ago | 6

| accepted

Answered
Data filtering(Cut from half length of index until next index )
data2 = data(cell2mat(accumarray(data(:,1),... (1:size(data,1))',[],@(x){x(1:ceil(numel(x)/2))})),:);

6 years ago | 2

| accepted

Answered
Manipulate matrix of different dimension
mm = [0 0 1;1 2 5;0 2 3 ;0 3 4; 0 4 5]; m = size(mm,1); n = max(mm(:)); lo = eye(m,n) ~= 0; M = zeros(m,n); [ii,~,v]=find...

6 years ago | 0

| accepted

Answered
Interleaving Vectors in MATLAB
Without loop: A = [1 2 4];B = [5 6 7]; C = [A;B]; C = C(:)'; with loop: for ii = numel(A):-1:1 C(2*ii-[0 1]) = [B(i...

6 years ago | 1

Answered
Double = in one line of code
b = 1000; zz = {b}; [a,c] = zz{[1,1]};

6 years ago | 2

Answered
Matrix calculation indexing conditional
Let A - your array (500 x 6): T = array2table(A); T_out = varfun(@sum,T,'InputVariables',2,'GroupingVariables',3:4);

6 years ago | 0

| accepted

Answered
Find a series of consecutive numbers and change index of them
[~,~,Data(:,1)] = unique(cumsum(Data(:,1)) - Data(:,2),'stable');

6 years ago | 1

Answered
How to apply a matlab code on a matrix if it already working on column vector.
[r,c] = size(MM); m = MM; m(m == 0) = nan; %lo -define the indices of the values that need to be changed: lo = fillmissing(...

6 years ago | 1

| accepted

Load more