Answered

How select a first value from the binary matrix ?

out = cumsum(cumsum(matrix)) == 1; or out = cumsum(matrix) == 1 & matrix;

How select a first value from the binary matrix ?

out = cumsum(cumsum(matrix)) == 1; or out = cumsum(matrix) == 1 & matrix;

9 hours 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});

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});

12 hours 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...

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...

23 hours 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);

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);

1 day 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')

Find Number of Elements in an Array

A = {'KM'; 'KL'; 'MN'; 'KM'; 'MM'; 'KL'}; out = varfun(@x,table(A),'GroupingVariables','A')

3 days 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,'; ...

Splitting one column into multiple columns

input = {'0.17 1.7285 0.001763792 1.000977 56651.41 0.000017652 DHT11, OK, 35.0,'; ...

6 days 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...

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 days ago | 1

| accepted

Answered

How to organize a table?

T = readtable('img1.txt'); out = varfun(@sum,T,'GroupingVariables',... {'time','cell_type'},'InputVariables','cell_t...

How to organize a table?

T = readtable('img1.txt'); out = varfun(@sum,T,'GroupingVariables',... {'time','cell_type'},'InputVariables','cell_t...

6 days ago | 0

Answered

work with matrix of words and number

T = readtable('txtfile.txt') T_out = varfun(@mean,T,'GroupingVariables','Var1');

work with matrix of words and number

T = readtable('txtfile.txt') T_out = varfun(@mean,T,'GroupingVariables','Var1');

7 days 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...

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...

7 days ago | 0

Answered

To generate alternate 0's and 1's

out = repelem(mod(0:numel(A)-1,2),A);

To generate alternate 0's and 1's

out = repelem(mod(0:numel(A)-1,2),A);

8 days 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))})),:);

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))})),:);

8 days 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...

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...

8 days ago | 0

| accepted

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);

Matrix calculation indexing conditional

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

9 days ago | 0

Answered

Find a series of consecutive numbers and change index of them

[~,~,Data(:,1)] = unique(cumsum(Data(:,1)) - Data(:,2),'stable');

Find a series of consecutive numbers and change index of them

[~,~,Data(:,1)] = unique(cumsum(Data(:,1)) - Data(:,2),'stable');

10 days 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(...

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(...

10 days ago | 1

| accepted

Answered

How to assign vectors to existing vector

Let X - interval for input data in 'vector_2' X = [0, 15]; x = setdiff(X(1):X(2),vector_1); % input data newvector_2 = vector...

How to assign vectors to existing vector

Let X - interval for input data in 'vector_2' X = [0, 15]; x = setdiff(X(1):X(2),vector_1); % input data newvector_2 = vector...

10 days ago | 0

Answered

List combinations and count how many it appears

YY = Y(W~=0,:); n = sum(YY>0,2); k = factorial(n)./factorial(n-2)/2; ie = cumsum(k); ib = ie - k + 1; zc = zeros(ie(end),2)...

List combinations and count how many it appears

YY = Y(W~=0,:); n = sum(YY>0,2); k = factorial(n)./factorial(n-2)/2; ie = cumsum(k); ib = ie - k + 1; zc = zeros(ie(end),2)...

13 days ago | 0

| accepted

Answered

Find values in a 3D array based on values in a seperate 3D array

lo = M_data == 1; [ii,jj,k] = ind2sub(size(M_data),find(lo)); output = [ii,jj,k,B_data(lo)];

Find values in a 3D array based on values in a seperate 3D array

lo = M_data == 1; [ii,jj,k] = ind2sub(size(M_data),find(lo)); output = [ii,jj,k,B_data(lo)];

14 days ago | 1

| accepted

Answered

Finding maximum value in a sequence

A = randi(1000,1,8); k = A(1); for ii = 2:numel(A) if k < A(ii) k = A(ii); end end

Finding maximum value in a sequence

A = randi(1000,1,8); k = A(1); for ii = 2:numel(A) if k < A(ii) k = A(ii); end end

14 days ago | 0

Answered

adding multiple arrays into one big array

s1 = size(A1); s2 = size(A2); s22 = max(s1(2),s2(2)); A = [A1,zeros(s1(1),s22 - s1(2));A2,zeros(s2(1),s22 - s2(2))];

adding multiple arrays into one big array

s1 = size(A1); s2 = size(A2); s22 = max(s1(2),s2(2)); A = [A1,zeros(s1(1),s22 - s1(2));A2,zeros(s2(1),s22 - s2(2))];

14 days ago | 1

| accepted

Answered

How to stop finding a value once it has been attained? (Find function inside a loop)

Please read about break in while loop.

How to stop finding a value once it has been attained? (Find function inside a loop)

Please read about break in while loop.

14 days ago | 0

Answered

How do I make a block diagonal matrix using blkdiag function for a N dimensions

C = repmat({A},n,1); out = blkdiag(C{:});

How do I make a block diagonal matrix using blkdiag function for a N dimensions

C = repmat({A},n,1); out = blkdiag(C{:});

18 days ago | 0

| accepted

Answered

Looping through numbers in file and adding first two numbers then next two and so on

conv(A,[1,1],'valid') or b = movsum(A,2); out = b(2:end);

Looping through numbers in file and adding first two numbers then next two and so on

conv(A,[1,1],'valid') or b = movsum(A,2); out = b(2:end);

20 days ago | 0

Answered

How can i classify my data?

a = [ 0.47 15.905 8.434 14.018 1010.803 1458.32 148.46 0.34 18.346 8.282 16.443 1012.711 1460.69 140.41 0.4 17.45...

How can i classify my data?

a = [ 0.47 15.905 8.434 14.018 1010.803 1458.32 148.46 0.34 18.346 8.282 16.443 1012.711 1460.69 140.41 0.4 17.45...

20 days ago | 0

| accepted

Answered

A doubt regarding a simple For loop indexing for certain rows only.

lo = a(:,3) == 4; ii = cumsum([0;diff(lo) == 1]).*lo; m = max(ii); ii(ii == 0) = m + 1; out = a(ii >= m,:);

A doubt regarding a simple For loop indexing for certain rows only.

lo = a(:,3) == 4; ii = cumsum([0;diff(lo) == 1]).*lo; m = max(ii); ii(ii == 0) = m + 1; out = a(ii >= m,:);

20 days ago | 1

Answered

Coud anyone help me to solve the issue.

One variant: [m,n] = size(A); [~,ii] = sort(rand(m-1,n)); B = A(2:end,:); An = [A(1,:);B(ii + (m-1)*(0:n-1))];% ATTENTION! I...

Coud anyone help me to solve the issue.

One variant: [m,n] = size(A); [~,ii] = sort(rand(m-1,n)); B = A(2:end,:); An = [A(1,:);B(ii + (m-1)*(0:n-1))];% ATTENTION! I...

20 days ago | 1

| accepted

Answered

Problem with matrices. Double and cell

for ii = 1:numel(CT) if ~iscell(CT{ii}) CT{ii} = num2cell(CT{ii}); end end T = cell2table(cat(2,CT{:})); w...

Problem with matrices. Double and cell

for ii = 1:numel(CT) if ~iscell(CT{ii}) CT{ii} = num2cell(CT{ii}); end end T = cell2table(cat(2,CT{:})); w...

21 days ago | 1

| accepted

Answered

How to convert a table into a structure

t2 = varfun(@(x){x(:)'},T,'GroupingVariables','Name'); TinStrr = t2(:,[1,3:end]); TinStrr.Properties.VariableNames = T.Propert...

How to convert a table into a structure

t2 = varfun(@(x){x(:)'},T,'GroupingVariables','Name'); TinStrr = t2(:,[1,3:end]); TinStrr.Properties.VariableNames = T.Propert...

21 days ago | 0

| accepted