Answered

How to repeat the condition for two matrices having different sizes?

[m,n,k] = size(A); z = size(B,3); h = k-mod(k,z); Ad3 = A(:,:,1:h); Ad2 = reshape(Ad3,prod([m,n,z]),[]); Bd2 = reshape(B,[]...

How to repeat the condition for two matrices having different sizes?

[m,n,k] = size(A); z = size(B,3); h = k-mod(k,z); Ad3 = A(:,:,1:h); Ad2 = reshape(Ad3,prod([m,n,z]),[]); Bd2 = reshape(B,[]...

14 hours ago | 0

Answered

select rows satisfying a particular condition

% Let A - your array. [ii,jj,v] = find(A); z = [ii,jj,v]; z = sortrows(z,[1,2]); out = accumarray(z(:,1),z(:,3),[],@(x){fu...

select rows satisfying a particular condition

% Let A - your array. [ii,jj,v] = find(A); z = [ii,jj,v]; z = sortrows(z,[1,2]); out = accumarray(z(:,1),z(:,3),[],@(x){fu...

15 hours ago | 1

| accepted

Answered

How to find the given index values in a array?

in R2016b T = readtable('Sheet2.xls','ReadVariableNames',0); lo = T{:,2:end} ~= 0 & ~isnan(T{:,2:end}); [ii,~] = find(lo); o...

How to find the given index values in a array?

in R2016b T = readtable('Sheet2.xls','ReadVariableNames',0); lo = T{:,2:end} ~= 0 & ~isnan(T{:,2:end}); [ii,~] = find(lo); o...

16 hours ago | 1

| accepted

Answered

Check common elements in two vectors and remove them from both the vectors leaving any duplicate. (Example Inside)

a1 = unique([A(:);B(:)]); s = size(a1); [~,iA] = ismember(A(:),a1); [~,iB] = ismember(B(:),a1); ii = (accumarray(iA,1,s) - a...

Check common elements in two vectors and remove them from both the vectors leaving any duplicate. (Example Inside)

a1 = unique([A(:);B(:)]); s = size(a1); [~,iA] = ismember(A(:),a1); [~,iB] = ismember(B(:),a1); ii = (accumarray(iA,1,s) - a...

1 day ago | 0

Answered

Row index exceeds matrix dimensions

T = array2table(A); m = varfun(@mean,T,'GroupingVariables',1); out = A; [~,~,ii] = unique(A(:,1)); out(:,2:end) = out(:,2:en...

Row index exceeds matrix dimensions

T = array2table(A); m = varfun(@mean,T,'GroupingVariables',1); out = A; [~,~,ii] = unique(A(:,1)); out(:,2:end) = out(:,2:en...

1 day ago | 1

| accepted

Answered

Using kron to create a large matrix

n = 11; A = [-4 2 0;1 -4 1;0 2 -4]; %main diagonal m = size(A,1); mn = m*n; o1 = ones(mn,1); out = full(spdiags([o1,repma...

Using kron to create a large matrix

n = 11; A = [-4 2 0;1 -4 1;0 2 -4]; %main diagonal m = size(A,1); mn = m*n; o1 = ones(mn,1); out = full(spdiags([o1,repma...

1 day ago | 0

| accepted

Answered

placement of elements from a matrix into another matrix

%{ block of code by Rupsana - initial and final submatrix values and initial matrix A: %} tot_row=5; tot_col=10; left_co...

placement of elements from a matrix into another matrix

%{ block of code by Rupsana - initial and final submatrix values and initial matrix A: %} tot_row=5; tot_col=10; left_co...

1 day ago | 0

Answered

A command like "unique" for matrices?

A=[1;2;3]; C=[4;5;6]; M = [repmat(A,2,1);C]; out = reshape(unique(reshape(M,3,[])','rows','stable')',[],1);

A command like "unique" for matrices?

A=[1;2;3]; C=[4;5;6]; M = [repmat(A,2,1);C]; out = reshape(unique(reshape(M,3,[])','rows','stable')',[],1);

3 days ago | 1

Answered

How can i seperate a string in all possible smaller ones without using for loops;.

a = 'ATGCA'; out = cellstr(a((1:end-1)' + [0, 1]));

How can i seperate a string in all possible smaller ones without using for loops;.

a = 'ATGCA'; out = cellstr(a((1:end-1)' + [0, 1]));

3 days ago | 0

Answered

How to make faster row-wise Matrix multiplication ?

Just use: out = permute(A,[3,2,1]).*B;

How to make faster row-wise Matrix multiplication ?

Just use: out = permute(A,[3,2,1]).*B;

4 days ago | 1

| accepted

Answered

short programs to subtracts rows from a matrix of n length

Z = squeeze(sqrt(sum((T - permute(X,[3,2,1])).^2,2)));

short programs to subtracts rows from a matrix of n length

Z = squeeze(sqrt(sum((T - permute(X,[3,2,1])).^2,2)));

4 days ago | 0

| accepted

Answered

How would I put this in a for loop ?

T = 1; % Period Vm = 1; % Voltage amplitude v = {@(t)Vm*sin(4*pi*t/T); @(t)2*Vm*sin(4*pi*t...

How would I put this in a for loop ?

T = 1; % Period Vm = 1; % Voltage amplitude v = {@(t)Vm*sin(4*pi*t/T); @(t)2*Vm*sin(4*pi*t...

4 days ago | 0

Answered

How do I create a random row matrix with some fixed positions?

a = [ 11 3 14]; b = 1:20; c = setdiff(b,a); n = numel(c); out = [a, c(randperm(n))];

How do I create a random row matrix with some fixed positions?

a = [ 11 3 14]; b = 1:20; c = setdiff(b,a); n = numel(c); out = [a, c(randperm(n))];

4 days ago | 0

| accepted

Answered

Rearrange matrix and concatenate cells

If your datadimer is table: A = datadimer{:,:}; sZ = 291; [m,n] = size(A); k = m/sZ; out = reshape(permute(reshape(A,sZ,k,n...

Rearrange matrix and concatenate cells

If your datadimer is table: A = datadimer{:,:}; sZ = 291; [m,n] = size(A); k = m/sZ; out = reshape(permute(reshape(A,sZ,k,n...

4 days ago | 0

Answered

return row index of values greater than 0 to a 3 dimensional array

[ii,jj] = find(A > 0); out = accumarray(ii,jj,[],@(x){sort(x)'}); out{:}

return row index of values greater than 0 to a 3 dimensional array

[ii,jj] = find(A > 0); out = accumarray(ii,jj,[],@(x){sort(x)'}); out{:}

4 days ago | 0

Answered

How to crop matrices at the maximal non-NaN values and then center the data

M = struct2cell(H); n = min(cellfun(@(x)find(any(isnan(x),2),1,'first')-1,M)); for jj = 1:numel(H) H(jj).matrix = H(jj).m...

How to crop matrices at the maximal non-NaN values and then center the data

M = struct2cell(H); n = min(cellfun(@(x)find(any(isnan(x),2),1,'first')-1,M)); for jj = 1:numel(H) H(jj).matrix = H(jj).m...

4 days ago | 1

| accepted

Answered

How to concentrate matrices of different row length (same column length) into one matrix by unfolding each of the matrices to the smallest row length conatining numbers not nan

M = struct2cell(H); n = min(cellfun(@(x)find(all(~isnan(x),2),1,'last'),M)); M = cellfun(@(x)reshape(x(1:n,:)',1,[]),M,'un',0)...

How to concentrate matrices of different row length (same column length) into one matrix by unfolding each of the matrices to the smallest row length conatining numbers not nan

M = struct2cell(H); n = min(cellfun(@(x)find(all(~isnan(x),2),1,'last'),M)); M = cellfun(@(x)reshape(x(1:n,:)',1,[]),M,'un',0)...

6 days ago | 1

| accepted

Answered

How can I extract the time column of a timetable

variant a = rand(20,6); date1 = datetime(2019,4,19) + hours(cumsum(70*rand(20,1))); TT = array2timetable(a,'RowTimes',date1...

How can I extract the time column of a timetable

variant a = rand(20,6); date1 = datetime(2019,4,19) + hours(cumsum(70*rand(20,1))); TT = array2timetable(a,'RowTimes',date1...

6 days ago | 1

| accepted

Answered

combining two text file with 100 equal number of header and body text

z = dir('file*_.txt'); zn = {z.name}; n = numel(zn); c = cell(n,1); for jj = 1:numel(zn) f1 = fopen(zn{jj}); k = t...

combining two text file with 100 equal number of header and body text

z = dir('file*_.txt'); zn = {z.name}; n = numel(zn); c = cell(n,1); for jj = 1:numel(zn) f1 = fopen(zn{jj}); k = t...

6 days ago | 0

| accepted

Answered

How to assign NaN for empty cells in an array?

Finalanswer = ismember(T.Icnum,moga);

How to assign NaN for empty cells in an array?

Finalanswer = ismember(T.Icnum,moga);

7 days ago | 1

Answered

How does Matrix(3002:2001:1999998)=0.4 works?

[ii,jj] = ind2sub([1000,2000],3002:2001:1999998); A = sparse(ii,jj,.4,1000,2000);

How does Matrix(3002:2001:1999998)=0.4 works?

[ii,jj] = ind2sub([1000,2000],3002:2001:1999998); A = sparse(ii,jj,.4,1000,2000);

7 days ago | 0

Answered

Matrix problem with my vectors

theta = (-5:5:25)';%+ n = numel(theta); N = [-0.906 1.43 2.78 4.20 5.03 5.28 -2.49 0.889 4.16 7.71 11.0 7.30 12.7]*4.45; FN_c...

Matrix problem with my vectors

theta = (-5:5:25)';%+ n = numel(theta); N = [-0.906 1.43 2.78 4.20 5.03 5.28 -2.49 0.889 4.16 7.71 11.0 7.30 12.7]*4.45; FN_c...

7 days ago | 0

Answered

How to subtract a number from a previous one

x = [1;.75;.5;.6]; n = filter(1,[1;1],x); or out = tril(toeplitz(x))*(-1).^(2:numel(x)+1).'; or n = x; for jj = 2:numel(...

How to subtract a number from a previous one

x = [1;.75;.5;.6]; n = filter(1,[1;1],x); or out = tril(toeplitz(x))*(-1).^(2:numel(x)+1).'; or n = x; for jj = 2:numel(...

8 days ago | 2

| accepted

Answered

how to adjust the conv filtered data same like origanal data?

con=conv(h,L,'same');

how to adjust the conv filtered data same like origanal data?

con=conv(h,L,'same');

8 days ago | 0

| accepted

Answered

how to count the number of element in observation and make summation?

K = B.TotalRevenue.*ones(size(B,1),3)/3; [a1,~,c1] = unique(B{:,1:3}); out = table(a1,accumarray(c1,K(:)),'v',{'opals','Revenu...

how to count the number of element in observation and make summation?

K = B.TotalRevenue.*ones(size(B,1),3)/3; [a1,~,c1] = unique(B{:,1:3}); out = table(a1,accumarray(c1,K(:)),'v',{'opals','Revenu...

8 days ago | 0

| accepted

Answered

Create This Matrix to N-Value

n = 3; out = flip(fullfact([n, n]),2) - 1; or [x,y] = ndgrid(0:n-1); out = [y(:),x(:)];

Create This Matrix to N-Value

n = 3; out = flip(fullfact([n, n]),2) - 1; or [x,y] = ndgrid(0:n-1); out = [y(:),x(:)];

9 days ago | 0

| accepted

Answered

How to extend/add elements to an array?

A = [2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ]; B = [3 2 3 5]; out = A(sort([find(A),repelem(find(A == 0),B)]));

How to extend/add elements to an array?

A = [2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ]; B = [3 2 3 5]; out = A(sort([find(A),repelem(find(A == 0),B)]));

9 days ago | 0

| accepted

Answered

sort a matrix depending on first row

out = sortrows(B.',1).' variant [~,inx]=sort(B(1,:)); out = B(:,inx);

sort a matrix depending on first row

out = sortrows(B.',1).' variant [~,inx]=sort(B(1,:)); out = B(:,inx);

15 days ago | 10

Answered

comparison of the datasets

T = readtable('example.xlsx','sheet',1); T2 = readtable('example.xlsx','sheet',2); R12 = unique([T2.R1;T2.R2+eps(1e3)]); C = ...

comparison of the datasets

T = readtable('example.xlsx','sheet',1); T2 = readtable('example.xlsx','sheet',2); R12 = unique([T2.R1;T2.R2+eps(1e3)]); C = ...

16 days ago | 0

| accepted