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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4 years ago | 0

Answered

tresholding by summing over a dimension of a matrix

k = size(micron_62frames,3); lo = sum(micron_62frames,3) > 13e6; micron_62frames(repmat(lo,1,1,k)) = nan;

tresholding by summing over a dimension of a matrix

k = size(micron_62frames,3); lo = sum(micron_62frames,3) > 13e6; micron_62frames(repmat(lo,1,1,k)) = nan;

4 years ago | 0

Answered

Delete end points from columns in a structure array

S = cell2struct(cellfun(@(x)x(3:end-2),struct2cell(S),'un',0),fieldnames(S));

Delete end points from columns in a structure array

S = cell2struct(cellfun(@(x)x(3:end-2),struct2cell(S),'un',0),fieldnames(S));

4 years ago | 1

| accepted

Answered

Averaging setions of a matix

out = cumsum(A)./(1:size(A,1))'; mnA = out(2:end,:);

Averaging setions of a matix

out = cumsum(A)./(1:size(A,1))'; mnA = out(2:end,:);

4 years ago | 1

Answered

How To Generate Non Repeating floating Random Numbers from 1 to 10

z = cumsum(rand(100,1)); mn = min(z); Z = 9/(max(z) - mn)*(z - mn) + 1; out = Z(randperm(100));

How To Generate Non Repeating floating Random Numbers from 1 to 10

z = cumsum(rand(100,1)); mn = min(z); Z = 9/(max(z) - mn)*(z - mn) + 1; out = Z(randperm(100));

4 years ago | 0

Answered

how to split data with 'or' condition ?

EDIT lo = [diff(tempdata_o4(:,4)) > 0;false]; i = cumsum(diff([false;lo]) == 1).*lo; C = accumarray(i + 1,(1:numel(i))',[],@(...

how to split data with 'or' condition ?

EDIT lo = [diff(tempdata_o4(:,4)) > 0;false]; i = cumsum(diff([false;lo]) == 1).*lo; C = accumarray(i + 1,(1:numel(i))',[],@(...

4 years ago | 0

| accepted

Answered

Creating a 2D matrix of non-zero modes from a 3D array

Q(Q == 0) = NaN; out = squeeze(mode(Q)); out(isnan(out)) = 0;

Creating a 2D matrix of non-zero modes from a 3D array

Q(Q == 0) = NaN; out = squeeze(mode(Q)); out(isnan(out)) = 0;

4 years ago | 0

| accepted

Answered

For each value in a vector, find the closest value in a cell and return index

sampled_freqs = [495 393 589]; cll = {'G4', 392; 'A4', 440; 'B4', 493.88; 'C5', 523.25; 'D5', 587.33}; [~,i] = min(abs(cat(1...

For each value in a vector, find the closest value in a cell and return index

sampled_freqs = [495 393 589]; cll = {'G4', 392; 'A4', 440; 'B4', 493.88; 'C5', 523.25; 'D5', 587.33}; [~,i] = min(abs(cat(1...

4 years ago | 2

| accepted

Answered

How can I make diamond shape with a matrix?

a = strel('diamond',250); out = kron(a.Neighborhood,[1 2 ; 3 4]);

How can I make diamond shape with a matrix?

a = strel('diamond',250); out = kron(a.Neighborhood,[1 2 ; 3 4]);

4 years ago | 1

Answered

Detecting length and number of occurrences in a logical array

Without Toolboxes and Fileexchanges a = accumarray(cumsum([0;diff(array1(:))] == 1).*array1(:)+1,1); out = a(2:end);

Detecting length and number of occurrences in a logical array

Without Toolboxes and Fileexchanges a = accumarray(cumsum([0;diff(array1(:))] == 1).*array1(:)+1,1); out = a(2:end);

4 years ago | 1

Answered

Manually interpolate a 2D array

a = rand(4,8);% Let a - your array F = griddedInterpolant(a); [i,j] = ndgrid(linspace(1,4,10),linspace(1,8,12)); % grid for ...

Manually interpolate a 2D array

a = rand(4,8);% Let a - your array F = griddedInterpolant(a); [i,j] = ndgrid(linspace(1,4,10),linspace(1,8,12)); % grid for ...

4 years ago | 1

| accepted

Answered

insert specific number of rows into matrix if condition is met and fill new cells with specific value

In your case: n = max(a(:,1)); out = [(1:n)',nan(n,1)]; out(a(:,1),2) = a(:,2);

insert specific number of rows into matrix if condition is met and fill new cells with specific value

In your case: n = max(a(:,1)); out = [(1:n)',nan(n,1)]; out(a(:,1),2) = a(:,2);

4 years ago | 1

| accepted

Answered

signature of values when exporting to excel?

A = A'; B = B'; C = C'; writetable(filename,table(A,B,C))

signature of values when exporting to excel?

A = A'; B = B'; C = C'; writetable(filename,table(A,B,C))

4 years ago | 0

| accepted