Answered
How to create a matrix with the data of a comparison, upper triangular the percentage of similarity and lower triangular the times that were compared?
a = permute(M,[3,2,1]); b = permute(M,[2,3,1]); x = sum(bsxfun(@eq,a,b),3); y = sum(~isnan(bsxfun(@plus,a,b)),3); ...

10 years ago | 1

| accepted

Answered
building matrix of a variable series in a for loop
a = rand(21); n = numel(a); m = ceil(sqrt(n)); out = reshape([a(:);nan(m^2-n,1)],m,[])';

10 years ago | 1

Answered
Accumarray error: First input SUBS must contain positive integer subscripts.
[uval,~,subs] = unique(X0012_50(:,20)-X0012_50(:,17)); temp_raw_JE50AO = accumarray(subs,~X0012_50(:,13)); out = [uval, ...

10 years ago | 1

Answered
How to crop a matrix/array based on a condition
A = [38 64 5 35 55 0 24 42 0 14 36 0 25 63 0 93 23 5 23 52 0 24 95 0 24 64 0 46 23 5 24 68 0 ...

10 years ago | 0

Answered
Rows mean collapse in big matrix
avarageNumb = 3; ma =[... 92 99 1 8 15 67 74 51 58 40 98 80 7 14 16 73 ...

10 years ago | 2

Answered
adding adjacent n elements in a matrix
A= [1 2 3 4;5 6 7 8;9 10 11 12 ; 13 14 15 16]; out = conv2(A,[1 1 1],'valid')

10 years ago | 2

| accepted

Answered
element by element subtraction using bsxfun
t = ones(size(a)); out = kron(a,t) - kron(t,a); or [m,n] = size(a); out = repelem(a,m,n) - repmat(a,m,n);

10 years ago | 1

Answered
how to find the elements in a matrix that follow a certain pattern
v =[0 0 0 5 6 7 8 0 0 0 12 13 0 0]; z = [[0;v(1:end-1)],v]; out = z([0;diff(all...

10 years ago | 1

Answered
Convert cell data type to single
cellfun(@single,a,'un',0)

10 years ago | 1

Answered
Merge data based on two columns
C = sortrows(unique([A(:,1:2);B(:,1:2)],'rows'),[2 1]); C = [C,nan(size(C,1),2)]; C(ismember(C(:,1:2),A(:,1:2),'rows'),3...

10 years ago | 0

| accepted

Answered
I am trying to write a program to solve a quadratic equation using loops and braces. see the images for the exact problem and my attempt
t = -9:.5:9; n = numel(t); out = zeros(n,1); for jj = 1:n if t(jj) < 0 out(jj) = 3*t(jj)^2 + 5; ...

10 years ago | 1

| accepted

Answered
Merge cell arrays by row
c = {'a', 'b', 'c'; '', 'd', 'e'; '', 'f', 'g'; 'h', 'i', 'j'; 'k', '', ''}; n = cu...

10 years ago | 1

| accepted

Answered
how to remove unwanted zeros from a vector
out = v(v | [1,v(1:end-1)])

10 years ago | 1

Answered
count values in a struct
t = cat(1,SetOfDataset(1).Interval2{:}); out = any(cellfun(@(x)any(x == 260957),t));

10 years ago | 1

| accepted

Answered
cumsum within a group
data=[1 10 1 10 1 10 1 10 2 10 2 15 2 20 3 5 4 10]; [~,~,c] = unique(data(:,1)); d =...

10 years ago | 0

Answered
Logical Indexing on a matrix with a vector of indices.
L(ismember(L,small_area)) = 0;

10 years ago | 1

| accepted

Answered
How can i create new column for data after each iteration of a for loop?
a = permute(bsxfun(@power,1+r(:),t(:)'),[3,2,1]); NPV = squeeze(sum(bsxfun(@rdivide,OCF,a),2)-500); with for..end loops ...

10 years ago | 0

Answered
Concatenate cell of arrays
out = cat(1,yourcells{:});

10 years ago | 0

Answered
Efficient Coding to save run time
sharpness = zeros(size(images)); for ii = 1 : 10 for jj = 1 : 4 for k = 1 : 5 sharpness(ii,jj,k)...

10 years ago | 1

Answered
Finding Annual Amplidute for each of multiple years
diff(reshape(yourdata,2,[]))'

10 years ago | 0

Answered
How to find different values of a function for i = 0 to 10
a = 1/2 ; b = 1/2 ; k = 1:10; hk = 2^(a+b+1)*gamma(k+a+1).*gamma(k+b+1)./((2*k+a+b+1).*gamma(k+1).*gamma(k+a+b+1));

10 years ago | 1

Answered
Suggestion for modifying code for combining matrices
Hi Ali! Please try it code: [m,n] = size(A); out = size([m,n]); aa = permute(cat(3,A,circshift(A,[0 -1])),[2 3 1]); ...

10 years ago | 2

| accepted

Answered
Can anyone help me to generate a matrix of 0's and 1's randomly in which each contains only one 1 like [ 0 1 0 0 0; 1 0 0 0 0; 0 0 0 1 0].
[~,ii] = sort(rand(3,5),2) out = ii == 1 or out = zeros(3,5) [m,n] = size(out); out(sub2ind([m,n],1:m,randper...

10 years ago | 1

| accepted

Answered
Is there a way to vectorize this for loop to speed up?
for j = 1 : size(R,1) for k = 1 : size(R,2) R(j,k)= (PR(j,k)*YF(k))+(C(k)*YI(k)*t(j)) ; end end ...

10 years ago | 2

| accepted

Answered
Finding a range in an array
x =[ 11 15 16 18 20 25] y =[10 20 30 40 50] a =[0 0 0 1 2 3 0 0 1 2 4 5 2 3 4 5 6 7 ...

10 years ago | 1

| accepted

Answered
Find largest array size in cell of many arrays
C = arrayfun(@(x)rand(randi([1 20],1,2)),(1:8)','un',0);% example [s,d] = cellfun(@size,C); out = max([s,d]);

10 years ago | 5

| accepted

Answered
Finding maximum value of y at some x
y=[6 8 11 10 31 9 11 31] x=[3 9 4 1 23 3 2 7] [a,~,c] = unique(y); ii = accumarray(c(:),(1:numel(c))',[],@(x){x})...

10 years ago | 0

Answered
Replace elements in vector by keeping specific positions
tup.*sorted_vector_combined

10 years ago | 0

| accepted

Answered
Integrating a multivariable function defined with logical operation
function f=test(x,y) if x>=0 && y>0 f=x+y; end if x<0 && y>0 f=-x+y; end end...

10 years ago | 0

| accepted

Load more