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

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

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

6 meses 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{:}]));

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

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

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

6 meses 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+)?(?=\}$)','...

6 meses 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); ...

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

7 meses 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)'

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

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

7 meses ago | 1

| accepted

Answered

how to generate matrix with any size in same pattern

n = 5; out = full(spdiags(ones(n,1)*[1 -2 1],-1:1,n,n)); or out = zeros(n); out([2:n+1:end,n+1:n+1:end]) = 1; out(1:n+1:end...

how to generate matrix with any size in same pattern

n = 5; out = full(spdiags(ones(n,1)*[1 -2 1],-1:1,n,n)); or out = zeros(n); out([2:n+1:end,n+1:n+1:end]) = 1; out(1:n+1:end...

7 meses ago | 0

Answered

Mean of certain elements within a matrix

Here A - your array (m x 6) [m,n] = size(A); i = repmat((0:m-1)',1,n-1); i(:,end-1:end) = circshift(i(:,end-1:end),-1); i = ...

Mean of certain elements within a matrix

Here A - your array (m x 6) [m,n] = size(A); i = repmat((0:m-1)',1,n-1); i(:,end-1:end) = circshift(i(:,end-1:end),-1); i = ...

7 meses ago | 0

Answered

Use of backslash while calculating the product of inverse of a matrix and another matrix

Maybe for "second way": xt = (D+omg*L)\((D*(1-omg)-omg*U)*xn+omg*((D+omg*L)\B));

Use of backslash while calculating the product of inverse of a matrix and another matrix

Maybe for "second way": xt = (D+omg*L)\((D*(1-omg)-omg*U)*xn+omg*((D+omg*L)\B));

7 meses ago | 0

| accepted

Answered

How to code this formula?

function rgb = HSVtoRGB(H,S,V) n = numel(H); C = V.*S; X = C .* (1 - abs(mod(H/60,2) - 1)); A = [C, X, zeros...

How to code this formula?

function rgb = HSVtoRGB(H,S,V) n = numel(H); C = V.*S; X = C .* (1 - abs(mod(H/60,2) - 1)); A = [C, X, zeros...

7 meses ago | 0

Answered

Vector output from a for loop

TMP = randi([-12,45],30,4); f = {@(x)0;@(x)x-9;@(x)1;@(x)3.33 - .083*x;@(x)0}; i = discretize(TMP,[-inf,9,10,28,40,inf]); o...

Vector output from a for loop

TMP = randi([-12,45],30,4); f = {@(x)0;@(x)x-9;@(x)1;@(x)3.33 - .083*x;@(x)0}; i = discretize(TMP,[-inf,9,10,28,40,inf]); o...

7 meses ago | 0

Answered

How to create 2D matrix from 3D without a loop?

[n,m,k] = size(A); [i,j] = ndgrid(1:n,1:m); C = A(sub2ind([n,m,k],i,j,B);

How to create 2D matrix from 3D without a loop?

[n,m,k] = size(A); [i,j] = ndgrid(1:n,1:m); C = A(sub2ind([n,m,k],i,j,B);

7 meses ago | 0

| accepted

Answered

Average of every nth value in a vector

Let A - your array 137255 x 1 n = numel(A); TT = timetable(A,'RowTimes',(0:n-1)'*saconds(.1)); out = retime(TT,'minutely','me...

Average of every nth value in a vector

Let A - your array 137255 x 1 n = numel(A); TT = timetable(A,'RowTimes',(0:n-1)'*saconds(.1)); out = retime(TT,'minutely','me...

7 meses ago | 0

Answered

CALCULATING THE MEAN OF HOZIRONTAL LINES IN A MATRIX VIA MATLAB

out = mean(A,2) % here A - your array 20 x 50

CALCULATING THE MEAN OF HOZIRONTAL LINES IN A MATRIX VIA MATLAB

out = mean(A,2) % here A - your array 20 x 50

7 meses ago | 0

| accepted

Answered

How to create a matrix from csv files?

[~,~,i] = unique(log_files); log_data = datafiles(i,:);

How to create a matrix from csv files?

[~,~,i] = unique(log_files); log_data = datafiles(i,:);

7 meses ago | 0

Answered

Need to sort the number in the increasing order using MATLAB script, shown as a sample text file.

T = readtable('new.txt') T = sortrows(T) writetable(T,'new2.txt','delimiter',',','WriteVariableNames',0)

Need to sort the number in the increasing order using MATLAB script, shown as a sample text file.

T = readtable('new.txt') T = sortrows(T) writetable(T,'new2.txt','delimiter',',','WriteVariableNames',0)

7 meses ago | 0

Answered

For Loop plot range of numbers

g = reshape(1.4:-.1:1.2,1,1,[]); n = [1.00, 0.975, 0.975, 0.950, 0.925]; M = linspace(1,10,15)'; g1 = g + 1; g_1 = g - 1; A...

For Loop plot range of numbers

g = reshape(1.4:-.1:1.2,1,1,[]); n = [1.00, 0.975, 0.975, 0.950, 0.925]; M = linspace(1,10,15)'; g1 = g + 1; g_1 = g - 1; A...

7 meses ago | 0

Answered

Replacing all elements in a row with zeros, if atleast one of the elements in the row is greater than 1

out = all(A <= 1,2).*A

Replacing all elements in a row with zeros, if atleast one of the elements in the row is greater than 1

out = all(A <= 1,2).*A

7 meses ago | 0

Answered

How can I change zeros matrix to 1 by specific points??

A = zeros(8, 8); A(1:3,1:3) = 1; A(5:8,5:8) = 1;

How can I change zeros matrix to 1 by specific points??

A = zeros(8, 8); A(1:3,1:3) = 1; A(5:8,5:8) = 1;

7 meses ago | 0

Answered

Counting the number of elements surrounding another element.

Let x - your array with ones and zeros: x = double(rand(10) > .45); out = conv2(double(~x),[1,1,1;1,0,1;1,1,1],'same');

Counting the number of elements surrounding another element.

Let x - your array with ones and zeros: x = double(rand(10) > .45); out = conv2(double(~x),[1,1,1;1,0,1;1,1,1],'same');

7 meses ago | 0

Answered

Finding max value and its position in ed matrix

[m,~,k] = size(C); [C_max_of_page,i] = max(reshape(C,[],k)); index_of_C_max_of_page = [mod(i-1,m)+1; ceil(i/m); (1:k)];

Finding max value and its position in ed matrix

[m,~,k] = size(C); [C_max_of_page,i] = max(reshape(C,[],k)); index_of_C_max_of_page = [mod(i-1,m)+1; ceil(i/m); (1:k)];

7 meses ago | 0