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

4 years 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]...

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

4 years 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

4 years 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,...

4 years 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)'

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

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

4 years 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;

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

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

4 years ago | 1

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

4 years 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;

4 years ago | 1

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

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

4 years 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 ' ! ...

4 years ago | 0

| accepted

Answered

How to solve the following exercise?

function out = find_neighbor(M,i,j) out = all(ismember(1:M(i,j)-1,M(i-1:i+1,j-1:j+1))); end

How to solve the following exercise?

function out = find_neighbor(M,i,j) out = all(ismember(1:M(i,j)-1,M(i-1:i+1,j-1:j+1))); end

4 years ago | 1

| accepted

Answered

Collect matrix values by using a "for" loop

Let A - your array. out = reshape(A.',[],1);

Collect matrix values by using a "for" loop

Let A - your array. out = reshape(A.',[],1);

4 years ago | 0

| accepted

Answered

How can I convert 2 column matrix to a cell array?

T = readtable('path\to\your\xls\file\matrix.xlsx','ReadVariableNames',0); T.Var3 = str2double(T.Var3); T = T(any(T{:,1:2} ~= 0...

How can I convert 2 column matrix to a cell array?

T = readtable('path\to\your\xls\file\matrix.xlsx','ReadVariableNames',0); T.Var3 = str2double(T.Var3); T = T(any(T{:,1:2} ~= 0...

4 years ago | 0

Answered

find common elements from cell array and remove it

out = A(~ismember([A{:}],[B{:}]));

find common elements from cell array and remove it

out = A(~ismember([A{:}],[B{:}]));

4 years ago | 0

| accepted

Answered

Adding values from columns 1:i for each column for a new matrix of the same size

Let A - your array (442 x 25) out = cumsum(A,2);

Adding values from columns 1:i for each column for a new matrix of the same size

Let A - your array (442 x 25) out = cumsum(A,2);

4 years ago | 0

| accepted

Answered

Find the median row of a binary column and replace the column with just the median row

I = imread('line.png'); bw = im2double(rgb2gray(I)); [i,j] = find(bw); [n,g] = findgroups(j); idx = floor(splitapply(@medi...

Find the median row of a binary column and replace the column with just the median row

I = imread('line.png'); bw = im2double(rgb2gray(I)); [i,j] = find(bw); [n,g] = findgroups(j); idx = floor(splitapply(@medi...

4 years ago | 0

Answered

Extracting values from a cell array into new arrays

CC = cat(3,C{:}); [m,n,k] = size(CC); Z = permute(repmat(b,1,1,n),[1,3,2]); out = CC(sub2ind([m,n,k],Z(:,:,2),repmat(1:n,size...

Extracting values from a cell array into new arrays

CC = cat(3,C{:}); [m,n,k] = size(CC); Z = permute(repmat(b,1,1,n),[1,3,2]); out = CC(sub2ind([m,n,k],Z(:,:,2),repmat(1:n,size...

4 years ago | 0

| accepted

Answered

How would I create a matrix from the following strings

T = readtable('Path\your\txt\file\ThinPlateNodes.txt'); T.Varend = str2double(regexp(T{:,end},'(\-)?\d+(\.\d+e\-\d+)?(?=\}$)','...

How would I create a matrix from the following strings

T = readtable('Path\your\txt\file\ThinPlateNodes.txt'); T.Varend = str2double(regexp(T{:,end},'(\-)?\d+(\.\d+e\-\d+)?(?=\}$)','...

4 years ago | 1

Answered

Finding Unique values for First Row of a Matrix

Let A - your array. output = A(1,:); for i = 2:numel(output) u = unique([output(1:i-1)';A(:,i)]); output(i) = u(i); ...

Finding Unique values for First Row of a Matrix

Let A - your array. output = A(1,:); for i = 2:numel(output) u = unique([output(1:i-1)';A(:,i)]); output(i) = u(i); ...

4 years ago | 0

| accepted

Answered

Index Exceeds Matrix Dimensions

T = readtable('sample.xlsx','ReadVariableNames',0); T.Properties.VariableNames = {'data','Longitude','Lattitude','altitude','De...

Index Exceeds Matrix Dimensions

T = readtable('sample.xlsx','ReadVariableNames',0); T.Properties.VariableNames = {'data','Longitude','Lattitude','altitude','De...

4 years ago | 0

| accepted

Answered

Creating a new matrix based on the data from other two matrices

out = reshape([reshape(g1',2,[],2);reshape(g2',3,[],2)],[],2)'

Creating a new matrix based on the data from other two matrices

out = reshape([reshape(g1',2,[],2);reshape(g2',3,[],2)],[],2)'

4 years ago | 1

| accepted

Answered

How to normalize a vector considering both maximum and the sum of values?

Please run follow m - file: SN = 8700; Nmx = 9900; nmn = fzero(@(x)func1(x,Nmx,SN,A),-10000); [~,N] = func1(nmn,Nmx,SN,A);...

How to normalize a vector considering both maximum and the sum of values?

Please run follow m - file: SN = 8700; Nmx = 9900; nmn = fzero(@(x)func1(x,Nmx,SN,A),-10000); [~,N] = func1(nmn,Nmx,SN,A);...

4 years ago | 0

Answered

Converting a cell array into a matrix of stipulated number of columns and rows

Let C - your cell array. if cells sizes are the same: out = reshape(cat(2,C{:}),[],4); if not the same: out = cell2mat(cel...

Converting a cell array into a matrix of stipulated number of columns and rows

Let C - your cell array. if cells sizes are the same: out = reshape(cat(2,C{:}),[],4); if not the same: out = cell2mat(cel...

4 years ago | 1

| accepted