Answered

I keep getting "Array indices must be positive integers or logical values."

x = (.993 : 0.01 : 1.283)'; f = polyval([7;-2;7;-14],x); g = polyval([-19; 3; 16; 8],x);

I keep getting "Array indices must be positive integers or logical values."

x = (.993 : 0.01 : 1.283)'; f = polyval([7;-2;7;-14],x); g = polyval([-19; 3; 16; 8],x);

7 days ago | 0

Answered

Using MAX function to determine which year had the highest value

T = readtable('2020-11-28.txt'); out = T(max(T.tropical_storms) == T.tropical_storms,:)

Using MAX function to determine which year had the highest value

T = readtable('2020-11-28.txt'); out = T(max(T.tropical_storms) == T.tropical_storms,:)

7 days ago | 1

Answered

I want to convert matrix into vector

a - your array [512 x 512 x 434] out = reshape(a,[],size(a,3))

I want to convert matrix into vector

a - your array [512 x 512 x 434] out = reshape(a,[],size(a,3))

9 days ago | 0

| accepted

Answered

Add interpolated data at a specific location in the main array.

a =tlv_lis_alt; input = interpol_alt; idx = [29;187]; k = numel(a); b = ones(k,1); [m,n] = size(input); lo = ~isnan(inpu...

Add interpolated data at a specific location in the main array.

a =tlv_lis_alt; input = interpol_alt; idx = [29;187]; k = numel(a); b = ones(k,1); [m,n] = size(input); lo = ~isnan(inpu...

13 days ago | 0

Answered

Interpolating data to find the values at NaN locations in the region.

[m,n] = size(v); [i,j] = ndgrid(1:m,1:n); lo = ~isnan(v); F = scatteredInterpolant(i(lo),j(lo),v(lo)); vout = F(i,j); lo2 =...

Interpolating data to find the values at NaN locations in the region.

[m,n] = size(v); [i,j] = ndgrid(1:m,1:n); lo = ~isnan(v); F = scatteredInterpolant(i(lo),j(lo),v(lo)); vout = F(i,j); lo2 =...

16 days ago | 0

| accepted

Answered

Finding real roots of cubic polynomial

e = 0.3; gama = 0.8; damp = 0.0031; A = 12; M = 2*10^-4; mu = 0.05/M; St = 0.2; AM = A*M; %parameters Ur = (4:0.1:6)';...

Finding real roots of cubic polynomial

e = 0.3; gama = 0.8; damp = 0.0031; A = 12; M = 2*10^-4; mu = 0.05/M; St = 0.2; AM = A*M; %parameters Ur = (4:0.1:6)';...

17 days ago | 1

| accepted

Answered

Remove rows/columns with same elements

[~,i] = unique(sort(A,2),'first','rows'); out = A(i,:);

Remove rows/columns with same elements

[~,i] = unique(sort(A,2),'first','rows'); out = A(i,:);

17 days ago | 0

| accepted

Answered

what is "Error using ==> mtimes Inner matrix dimensions must agree."

t = 0:0.05:4; y = t.^2./ (t+1) + 3*exp(-4*t).*cos(5*t) - 2*exp(-3*t)./sin(2*t);

what is "Error using ==> mtimes Inner matrix dimensions must agree."

t = 0:0.05:4; y = t.^2./ (t+1) + 3*exp(-4*t).*cos(5*t) - 2*exp(-3*t)./sin(2*t);

17 days ago | 0

Answered

Matrix multiplication error using '.*'

r = randi(100,66); t = reshape(0:1/55:1,1,1,[]); e = exp(2*pi*i*13*t); t = r.*e;

Matrix multiplication error using '.*'

r = randi(100,66); t = reshape(0:1/55:1,1,1,[]); e = exp(2*pi*i*13*t); t = r.*e;

17 days ago | 0

Answered

rearrangement rows of matrices

A = reshape(1:75,15,[]); a = 5; m = size(A,1); B = reshape(permute(reshape(A,a,m/a,[]),[1,3,2]),a,[]);

rearrangement rows of matrices

A = reshape(1:75,15,[]); a = 5; m = size(A,1); B = reshape(permute(reshape(A,a,m/a,[]),[1,3,2]),a,[]);

18 days ago | 0

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

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

8 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

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

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

8 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]'; ...

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

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

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

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

8 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,[]));

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

8 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]; ...

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

8 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(:)),...

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

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

9 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

9 months ago | 0

| accepted