Answered

How can I convert a cell array into a double array

out = cell2mat(cellfun(@(x)cell2mat(cat(1,x{:})).',CellMatrix,'un',0));

How can I convert a cell array into a double array

out = cell2mat(cellfun(@(x)cell2mat(cat(1,x{:})).',CellMatrix,'un',0));

15 hours ago | 1

| accepted

Answered

Checkin for equal values in the same column

T = array2table(A); m = varfun(@mean,T,'GroupingVariables',1); out = A; out(:,2:end) = out(:,2:end) - m{A(:,1),3:end};

Checkin for equal values in the same column

T = array2table(A); m = varfun(@mean,T,'GroupingVariables',1); out = A; out(:,2:end) = out(:,2:end) - m{A(:,1),3:end};

20 hours ago | 0

| accepted

Answered

How to calculate sum of all the possible combinations of two vector elements

log(kron(exp(B),exp(A)))

How to calculate sum of all the possible combinations of two vector elements

log(kron(exp(B),exp(A)))

3 days ago | 0

| accepted

Answered

creating a nested loop to change values within a for loop

[ii,k,jj] = size(young_50); yy = permute(young_50,[2,3,1]); y1 = reshape(yy(:,[1,3:end],:),k,[]); b = squeeze(yy(:,2,:)); p ...

creating a nested loop to change values within a for loop

[ii,k,jj] = size(young_50); yy = permute(young_50,[2,3,1]); y1 = reshape(yy(:,[1,3:end],:),k,[]); b = squeeze(yy(:,2,:)); p ...

3 days ago | 0

Answered

find row with certain value and put in cell

z = B.*permute(A,[1,3,2]); [~,jj] = ndgrid(1:size(A,1)*2,1:size(A,2)); out = accumarray(jj(:),z(:),[],@(x){unique(x(x~=0))});

find row with certain value and put in cell

z = B.*permute(A,[1,3,2]); [~,jj] = ndgrid(1:size(A,1)*2,1:size(A,2)); out = accumarray(jj(:),z(:),[],@(x){unique(x(x~=0))});

4 days ago | 0

Answered

How can I equate all values of one vector to another and get the value ? Please find the example below

dataA = [-496,-636,-52,175,-84,-248,-555,-423,34,-174]'; dataB = [-0.399609375000000,-0.512402343750000,-0.0418945312500000,......

How can I equate all values of one vector to another and get the value ? Please find the example below

dataA = [-496,-636,-52,175,-84,-248,-555,-423,34,-174]'; dataB = [-0.399609375000000,-0.512402343750000,-0.0418945312500000,......

4 days ago | 0

| accepted

Answered

How to generate all pairwise differences between two vectors

out = (a(:)' - b(:))./b(:)*100;

How to generate all pairwise differences between two vectors

out = (a(:)' - b(:))./b(:)*100;

7 days ago | 0

Answered

How to find first non repeated (unique) character in a string?

z = 'hello'; [a,~,c] = unique(z,'stable'); out = a(find(accumarray(c,1) == 1,1));

How to find first non repeated (unique) character in a string?

z = 'hello'; [a,~,c] = unique(z,'stable'); out = a(find(accumarray(c,1) == 1,1));

8 days ago | 1

Answered

extract the 16 elements (4 by 4 matrix) from a big matrix

n = 4; s = size(A,1); out = reshape(A',s,n,[]); Here: out(:,:,1) -> B, out(:,:,2) -> C, out(:,:,3) -> D and etc.

extract the 16 elements (4 by 4 matrix) from a big matrix

n = 4; s = size(A,1); out = reshape(A',s,n,[]); Here: out(:,:,1) -> B, out(:,:,2) -> C, out(:,:,3) -> D and etc.

10 days ago | 0

Answered

how to check symmetric for vector or array with 1 dimension

isequal(A(:),flip(A(:)));

how to check symmetric for vector or array with 1 dimension

isequal(A(:),flip(A(:)));

10 days ago | 0

Answered

How to compare each element of a matrix with a number? And then star it out

a = [1 2 3 4 5 6 7]'; c = 6; lo = a >= c; z = ["","*"]'; out = a + z(lo+1);

How to compare each element of a matrix with a number? And then star it out

a = [1 2 3 4 5 6 7]'; c = 6; lo = a >= c; z = ["","*"]'; out = a + z(lo+1);

14 days ago | 1

Answered

How to generate all pairwise differences between two vectors

out = a(:) - b(:)';

How to generate all pairwise differences between two vectors

out = a(:) - b(:)';

15 days ago | 1

Answered

Find common elements between two vectors and extract data from matrix (vectorized)

A3 = fix(A2.*(10.^-floor(log10(A2)))); [ii,~] = find(squeeze(all(A3==reshape(B,1,1,[])))); [~,~,c] = unique(ii,'stable'); jj ...

Find common elements between two vectors and extract data from matrix (vectorized)

A3 = fix(A2.*(10.^-floor(log10(A2)))); [ii,~] = find(squeeze(all(A3==reshape(B,1,1,[])))); [~,~,c] = unique(ii,'stable'); jj ...

17 days ago | 0

| accepted

Answered

Matrix manipulation (matrix A to B format)

AA = [A,repmat([1,0],size(A,1),1)]; A3 = reshape(kron(AA,[1;1]),[],2,2); A3(2:2:end,:,:) = flip(A3(2:2:end,:,:),2).*[-1,1]; B...

Matrix manipulation (matrix A to B format)

AA = [A,repmat([1,0],size(A,1),1)]; A3 = reshape(kron(AA,[1;1]),[],2,2); A3(2:2:end,:,:) = flip(A3(2:2:end,:,:),2).*[-1,1]; B...

17 days ago | 1

| accepted

Answered

Program that separates even and odd numbers and shows them in two vectors.

n = (1:100)'; lo = rem(n,2)==1; pares = n(~lo); impares = n(lo);

Program that separates even and odd numbers and shows them in two vectors.

n = (1:100)'; lo = rem(n,2)==1; pares = n(~lo); impares = n(lo);

17 days ago | 1

| accepted

Answered

how to detect index of the max amplitude?

[out,ii] = max(A); out_ind = index(ii);

how to detect index of the max amplitude?

[out,ii] = max(A); out_ind = index(ii);

21 days ago | 1

| accepted

Answered

how to create this vector?

X=[0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1]; Y=[3 6 5]; Y2 = [0,Y]; out = Y2(bwlabel(X) + 1);

how to create this vector?

X=[0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1]; Y=[3 6 5]; Y2 = [0,Y]; out = Y2(bwlabel(X) + 1);

22 days ago | 1

| accepted

Answered

Scatter data interpolation of a column matrix

T = readtable('torque.xlsx','ReadV',0); torquei = xlsread('torquei.xlsx'); throttle= [0 2.5 5 10 15 20 30 40 50 60 65 70 75 80...

Scatter data interpolation of a column matrix

T = readtable('torque.xlsx','ReadV',0); torquei = xlsread('torquei.xlsx'); throttle= [0 2.5 5 10 15 20 30 40 50 60 65 70 75 80...

23 days ago | 0

| accepted

Answered

extract elements from four matrices and create new matrix

Let A,B,C,D - your matrix (4 x 4). out = reshepe(permute(cat(3,A,B,C,D),[3,1,2]),2,2,[]); or out = reshepe(permute(cat(3,A,B,...

extract elements from four matrices and create new matrix

Let A,B,C,D - your matrix (4 x 4). out = reshepe(permute(cat(3,A,B,C,D),[3,1,2]),2,2,[]); or out = reshepe(permute(cat(3,A,B,...

23 days ago | 0

Answered

Replace elements of a matrix

A = [1 4 3; 2 3 2;4 2 1;10,7,1]; b = [4 ,10 3 , 15 2 ,20 1 , 30]; [lo,ii] = ismember(A,b(:,1)); A(lo) = b(ii(lo),2); ...

Replace elements of a matrix

A = [1 4 3; 2 3 2;4 2 1;10,7,1]; b = [4 ,10 3 , 15 2 ,20 1 , 30]; [lo,ii] = ismember(A,b(:,1)); A(lo) = b(ii(lo),2); ...

23 days ago | 2

| accepted

Answered

How to linearly change values in matrix

toeplitz(1:-.1:.6) or 1 - abs((1:5) - (1:5)')*.1

How to linearly change values in matrix

toeplitz(1:-.1:.6) or 1 - abs((1:5) - (1:5)')*.1

24 days ago | 0

| accepted

Answered

How to merge a datetime array with a table

out = table2timetable(Result,'RowTimes',DT);

How to merge a datetime array with a table

out = table2timetable(Result,'RowTimes',DT);

26 days ago | 0

| accepted

Answered

Element wise multiplication array-matrix between each element of the array with the whole matrix

result = kron(A(:),B)

Element wise multiplication array-matrix between each element of the array with the whole matrix

result = kron(A(:),B)

26 days ago | 1

| accepted

Answered

How to chang matrix size 81x81x30 to 81x81x32 by add row

daily_avg_u(:,:,end + (1:2)) = zeros([size(daily_avg_u(:,:,1)),2]);

How to chang matrix size 81x81x30 to 81x81x32 by add row

daily_avg_u(:,:,end + (1:2)) = zeros([size(daily_avg_u(:,:,1)),2]);

26 days ago | 1

| accepted

Answered

Averaging and summing parts of a column based on date

T = readtable('Matlab question.xlsx','Ra','A2:B109','ReadV',0); out = rowfun(@tempfun,T,'G','Var1',... 'OutputV',... ...

Averaging and summing parts of a column based on date

T = readtable('Matlab question.xlsx','Ra','A2:B109','ReadV',0); out = rowfun(@tempfun,T,'G','Var1',... 'OutputV',... ...

28 days ago | 0

Answered

I have a 18x3 timetable and i want to get the average of G and T columns from 1-9 and 10-18 then put them in a new table 2x3 but i don't know how to do it

out = varfun(@mean,e,'G','DATE_UTC');

I have a 18x3 timetable and i want to get the average of G and T columns from 1-9 and 10-18 then put them in a new table 2x3 but i don't know how to do it

out = varfun(@mean,e,'G','DATE_UTC');

29 days ago | 0

| accepted

Answered

I am getting error in integrating a function from 0 to infinity wrt x. Kindly help.

Try q = integral(fun,0,Inf,'ArrayValued',1); but in your case the result is a zero vector, due to value of the gamma = 0.

I am getting error in integrating a function from 0 to infinity wrt x. Kindly help.

Try q = integral(fun,0,Inf,'ArrayValued',1); but in your case the result is a zero vector, due to value of the gamma = 0.

29 days ago | 0

| accepted

Answered

grouped average in arrays

Old MATLAB T = table(A(:),repelem(string(['a':'d','b']'),[3,3,2,3,1]),'v',{'A','B'}); outT = varfun(@mean,T,'G',2);

grouped average in arrays

Old MATLAB T = table(A(:),repelem(string(['a':'d','b']'),[3,3,2,3,1]),'v',{'A','B'}); outT = varfun(@mean,T,'G',2);

29 days ago | 0

Answered

Sum specific rows of an array

A = [0.2 2 3 1 3 4 1 4 6 0.8 4 6 2 5 1 1 6 2 0.4 6 2]; [a,~,c] = uniq...

Sum specific rows of an array

A = [0.2 2 3 1 3 4 1 4 6 0.8 4 6 2 5 1 1 6 2 0.4 6 2]; [a,~,c] = uniq...

29 days ago | 0

| accepted