Answered

Need to loop through 2 vectors of 0's and 1's, if a 1 occurs in vector 1 before vector 2, then i need to use a specific eqn. if vector 2 has a 1 before vector 1, then i need to use a seperate eqn.Each vector is the same size.

Let a - your Pre_spiketime, b - Post_spiketime. d = a(:) - b(:); e = d.*[true;diff(d)~=0]; t = e ~= 0; l = cumsum(t); out =...

Need to loop through 2 vectors of 0's and 1's, if a 1 occurs in vector 1 before vector 2, then i need to use a specific eqn. if vector 2 has a 1 before vector 1, then i need to use a seperate eqn.Each vector is the same size.

Let a - your Pre_spiketime, b - Post_spiketime. d = a(:) - b(:); e = d.*[true;diff(d)~=0]; t = e ~= 0; l = cumsum(t); out =...

6 months ago | 0

Answered

Counting how many times a number occured after a specific number

accumarray(hankel(S(1:end-1),S(end-1:end)),1)

Counting how many times a number occured after a specific number

accumarray(hankel(S(1:end-1),S(end-1:end)),1)

7 months ago | 0

Answered

Trying to create polyval but mine only works for a single value of x , how to make it work for an array?

function Y = polyvalali(A,x) Y = x(:) .^ (numel(A)-1:-1:0) * A(:); end

Trying to create polyval but mine only works for a single value of x , how to make it work for an array?

function Y = polyvalali(A,x) Y = x(:) .^ (numel(A)-1:-1:0) * A(:); end

7 months ago | 1

Answered

Get max and min of each row in a table and create a new table with those values

Let A - your table. [~,i] = sort(A{1,2:end}); out = A(:,[1,1+i([end:-1:end-2,3:-1:1])]);

Get max and min of each row in a table and create a new table with those values

Let A - your table. [~,i] = sort(A{1,2:end}); out = A(:,[1,1+i([end:-1:end-2,3:-1:1])]);

7 months ago | 0

Answered

Perform AND operations with multiple matrices

i = find(all(cat(3,M{:}) == reshape(c,1,1,[]),3));

Perform AND operations with multiple matrices

i = find(all(cat(3,M{:}) == reshape(c,1,1,[]),3));

7 months ago | 0

Answered

Delete certain entries in a 3D matrix

A = randi(200,3,30,4);% Let A - our array [3 x 30 x 4] idx = [1,1,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2]'; ...

Delete certain entries in a 3D matrix

A = randi(200,3,30,4);% Let A - our array [3 x 30 x 4] idx = [1,1,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2]'; ...

7 months ago | 0

| accepted

Answered

generating sequence number with time sampling

out = cumsum([0;rem(0:23,2)' + 2]); for "t = 1:1000": t = (1:1000); tt = mod(t,2); out = cumsum([0;2 + tt(2:end)]);

generating sequence number with time sampling

out = cumsum([0;rem(0:23,2)' + 2]); for "t = 1:1000": t = (1:1000); tt = mod(t,2); out = cumsum([0;2 + tt(2:end)]);

7 months ago | 0

| accepted

Answered

Problems with double looping

Just: ii = 2:8; jj = -(6:12); debt = 132.4 - jj(:) + ii(:)'; debt = debt(:); or with for-loop: ii = 2:8; jj = -(6:12); d...

Problems with double looping

Just: ii = 2:8; jj = -(6:12); debt = 132.4 - jj(:) + ii(:)'; debt = debt(:); or with for-loop: ii = 2:8; jj = -(6:12); d...

7 months ago | 0

| accepted

Answered

Count the number of occurrences in a string vector

s = string({'A';'A';'B';'A';'B';'B';'C';'A';'C'}); out = zeros(numel(s),1); [~,~,c] = unique(s); for i = 1:max(c) lo =...

Count the number of occurrences in a string vector

s = string({'A';'A';'B';'A';'B';'B';'C';'A';'C'}); out = zeros(numel(s),1); [~,~,c] = unique(s); for i = 1:max(c) lo =...

7 months ago | 1

| accepted

Answered

Number of sequences with 3 or more ascending numbers

lo = diff(v) > 0; lo = [~lo(1);lo]; lo2 = [lo(2:end);false]|lo; i = cumsum(lo == 0 & lo2).*lo2; j = accumarray(i + 1,1); C ...

Number of sequences with 3 or more ascending numbers

lo = diff(v) > 0; lo = [~lo(1);lo]; lo2 = [lo(2:end);false]|lo; i = cumsum(lo == 0 & lo2).*lo2; j = accumarray(i + 1,1); C ...

7 months ago | 0

Answered

Processing 2D into 3D matrix

modeshapes = sin(phi + reshape(x,1,1,[]));

Processing 2D into 3D matrix

modeshapes = sin(phi + reshape(x,1,1,[]));

7 months ago | 0

| accepted

Answered

Adding rows to matrix conditionally

out = [(x(1,1):x(end,1))',repelem(x(:,2),[diff(x(:,1));1])];

Adding rows to matrix conditionally

out = [(x(1,1):x(end,1))',repelem(x(:,2),[diff(x(:,1));1])];

7 months ago | 0

Answered

Fill in missing NaNs

This question is a repeat of this question: x = [1;2;3;4;nan;nan;nan;nan;nan;5;7;8;nan;nan;nan;nan;11;11;12;nan;nan;nan;15]; ...

Fill in missing NaNs

This question is a repeat of this question: x = [1;2;3;4;nan;nan;nan;nan;nan;5;7;8;nan;nan;nan;nan;11;11;12;nan;nan;nan;15]; ...

7 months ago | 1

Answered

Filling in missing points

In R2016b: T = readtable('weather_laverton.xlsx','Sheet',1); TT = table2timetable(T); TTout = fillmissing(TT,'linear'); Add ...

Filling in missing points

In R2016b: T = readtable('weather_laverton.xlsx','Sheet',1); TT = table2timetable(T); TTout = fillmissing(TT,'linear'); Add ...

7 months ago | 0

Answered

How to get all values existing in arrays/matrices?

[a,~,c] = unique(reshape(myArray',[],1),'stable'); out = [a, accumarray(c,1)]; or out = varfun(@(x)x,array2table(myArray(:)),...

How to get all values existing in arrays/matrices?

[a,~,c] = unique(reshape(myArray',[],1),'stable'); out = [a, accumarray(c,1)]; or out = varfun(@(x)x,array2table(myArray(:)),...

7 months ago | 1

| accepted

Answered

find values in vector present in cell array

out = cell(size(cA)); for i = 1:numel(out) x = cA{i}'; [~,out{i}] = ismember(x(:)',V); end or with cellfun [~,out]...

find values in vector present in cell array

out = cell(size(cA)); for i = 1:numel(out) x = cA{i}'; [~,out{i}] = ismember(x(:)',V); end or with cellfun [~,out]...

7 months ago | 1

| accepted

Answered

how to extract n rows in a matrix column iteratively?

out = num2cell(reshape(A,3,[]),1); or out = accumarray(ceil((1:numel(A))'/3),A,[],@(x){x});

how to extract n rows in a matrix column iteratively?

out = num2cell(reshape(A,3,[]),1); or out = accumarray(ceil((1:numel(A))'/3),A,[],@(x){x});

8 months ago | 0

Answered

DOT type element wise multiplication of two 2-D matrices with array expansion (3-D)

out3D = A .* permute(B,[3,1,2]); % for R2016a and later out3D = bsxfun(@times,A, permute(B,[3,1,2])); % earlier R2016a

DOT type element wise multiplication of two 2-D matrices with array expansion (3-D)

out3D = A .* permute(B,[3,1,2]); % for R2016a and later out3D = bsxfun(@times,A, permute(B,[3,1,2])); % earlier R2016a

8 months ago | 0

| accepted

Answered

Convert a vector to single element

signal = dec2bin((0:255)'); or fullfact([2 2 2 2 2 2 2]) - 1; in your case for i = 256:-1:1 signal(i,:) = dec2bin(i-1,...

Convert a vector to single element

signal = dec2bin((0:255)'); or fullfact([2 2 2 2 2 2 2]) - 1; in your case for i = 256:-1:1 signal(i,:) = dec2bin(i-1,...

8 months ago | 1

| accepted

Answered

Extracting a vector from elements of a matrices that are in a cell structure.

V = cat(1,C{:}); V(:,1)' V(:,2)'

Extracting a vector from elements of a matrices that are in a cell structure.

V = cat(1,C{:}); V(:,1)' V(:,2)'

8 months ago | 0

| accepted

Answered

converting a matrix sequentially in to single column

Let A - your array. k = 30; [m,n] = size(A); out = reshape(permute(reshape(A,k,[],n),[1,3,2]),[],n);

converting a matrix sequentially in to single column

Let A - your array. k = 30; [m,n] = size(A); out = reshape(permute(reshape(A,k,[],n),[1,3,2]),[],n);

8 months ago | 0

| accepted

Answered

How to convert datenum to datetime in a MATLAB Table

a=[2 737735.191331019 6 737735.182129630 3 737735.182013889 7 737735.141481482]; T...

How to convert datenum to datetime in a MATLAB Table

a=[2 737735.191331019 6 737735.182129630 3 737735.182013889 7 737735.141481482]; T...

9 months ago | 0

Answered

Unique Number Assignment To Each Time

a=[1.1, 1.1, 1.1, 1.2, 1.2, 1.2, 2.1, 2.1, 2.1]' [i,g]=findgroups(a); out = i - 1;

Unique Number Assignment To Each Time

a=[1.1, 1.1, 1.1, 1.2, 1.2, 1.2, 2.1, 2.1, 2.1]' [i,g]=findgroups(a); out = i - 1;

9 months ago | 0

| accepted

Answered

Find max value with multiple conditions

T=readtable('wave height data.xlsx'); [r,rn] = findgroups(T(:,1)); [c,cn] = findgroups(T(:,2)); out = accumarray([r,c],T.Wave...

Find max value with multiple conditions

T=readtable('wave height data.xlsx'); [r,rn] = findgroups(T(:,1)); [c,cn] = findgroups(T(:,2)); out = accumarray([r,c],T.Wave...

9 months ago | 1

| accepted

Answered

Count smaller than 15 cells in the table coulumns

T = varfun(@funir,results_excel,'I',2:5); T.Properties.VariableNames = results_excel.Properties.VariableNames(2:end); T.statio...

Count smaller than 15 cells in the table coulumns

T = varfun(@funir,results_excel,'I',2:5); T.Properties.VariableNames = results_excel.Properties.VariableNames(2:end); T.statio...

9 months ago | 0

Answered

Is there a way to find the max value in an array without using the "max" command?

Let A - your array. B = A(:); max_value = B(all(B - B' <= 0));

Is there a way to find the max value in an array without using the "max" command?

Let A - your array. B = A(:); max_value = B(all(B - B' <= 0));

9 months ago | 0

Answered

how can i find the average of every single raw in a matrix without using sum or mean function ?

n = size(sc,2); out = sc*ones(n,1)/n;

how can i find the average of every single raw in a matrix without using sum or mean function ?

n = size(sc,2); out = sc*ones(n,1)/n;

9 months ago | 0

Answered

Consolidating counts & sum by Year Range

y = [2001, 2002, 2005 2003, 2004, 2007]; A = [2001 2002 2001 2003 2003 2003 2004 2004 2004 2004 2004 2007; 1 ...

Consolidating counts & sum by Year Range

y = [2001, 2002, 2005 2003, 2004, 2007]; A = [2001 2002 2001 2003 2003 2003 2004 2004 2004 2004 2004 2007; 1 ...

9 months ago | 1

| accepted

Answered

Convert Columns Arrays to numeric

...how can I know the data type of the columns? varfun(@class,combine) solution: load('data.mat') combine = [combine,rowfu...

Convert Columns Arrays to numeric

...how can I know the data type of the columns? varfun(@class,combine) solution: load('data.mat') combine = [combine,rowfu...

9 months ago | 1

| accepted

Answered

Matrix dimensions must agree error in if loop

day = input('What day is today? -> ', 's'); lo = any(strcmpi(day,{'saturday','sunday'})); if lo disp(['Its ' day ' ! ...

Matrix dimensions must agree error in if loop

day = input('What day is today? -> ', 's'); lo = any(strcmpi(day,{'saturday','sunday'})); if lo disp(['Its ' day ' ! ...

9 months ago | 0

| accepted