Answered
How to effectively get the mean for every three consecutive outputs?
If you want to avoid reshape, nd arrays, etc... C = [zeros(1,size(A,2)); cumsum(A,1)]; M3 = diff(C(1:3:end,:),1,1)/3 ...

7 years ago | 0

Answered
A question about generating a matrix
clear A A(n) = 1

7 years ago | 0

Answered
reduce execution time in matlab
Please try to replace the DCCA with this function function [CovXY,VarX,VarY]=DCCA_vec(Data1,Data2,n) X=cumsum(Data1)...

7 years ago | 0

| accepted

Answered
HISTCOUNTS a true replacement of HISTC?
Third solution, may be the best in term of speed/memory % replacement of [n,i] = histc(x,edges,dim); [~,~,i] = histc...

7 years ago | 0

| accepted

Answered
how to index zeros or remove zeros for indexing?
D=zeros(length(A),length(B)) D(A>0,B>0)=C(A(A>0),B(B>0))

7 years ago | 0

| accepted

Answered
Frequency of data occurrence using histc
You might take a look at uniquetol()

7 years ago | 0

Answered
Logical indexing based on intervals
For general case, meaning without any assumption about the intervals; you can use a function in <https://fr.mathworks.com/matla...

7 years ago | 0

Answered
Find closest value in array y of n columns corresponding to values from array x with m columns.
A_time = A(:,1); B_time = B(:,1); [At,ia] = unique(A_time); ib = interp1(At,ia,B_time,'nearest','extrap'); C = A(i...

7 years ago | 1

| accepted

Answered
HISTCOUNTS a true replacement of HISTC?
Another solution of replacement, still long, but consumes less memory than my first solution at the cost of array permutations: ...

7 years ago | 0

Answered
HISTCOUNTS a true replacement of HISTC?
OK, here is the answer of my own question. The replacement of [n,i] = histc(x, edges, dim); is [~,~,i] = histco...

7 years ago | 1

Answered
How to generate a 2D sphere matrix and not a disc
phi=linspace(0,2*pi,512); theta=linspace(0,pi/2,512).'; x=cos(phi).*cos(theta); y=sin(phi).*cos(theta); z=ones(siz...

7 years ago | 2

Question


HISTCOUNTS a true replacement of HISTC?
Since few latest releases we get the code warning "histc is not recommended. Use histcounts instead". However how to replace ...

7 years ago | 4 answers | 1

4

answers

Answered
Generate Gaussian Mixture Distribution samples for PEM
% Characteristics of your GM distribution mu = [1,2,5] sigma = [0.2, 0.3, 0.4]; A = [5 3 2]; % number of samples...

7 years ago | 0

| accepted

Answered
Logical indexing based on intervals
any(EMG_times>=t_comb_5(:,1)' & EMG_times<=t_comb_5(:,2)',2) Or if you run for old matlab release: any(bsxfun(@ge,EMG...

7 years ago | 0

| accepted

Answered
Binning of data except from histcounts?
ndivisions=4; n = length(A); partnum = floor(1+(0:n-1)/n*ndivisions); n1 = accumarray(partnum(:),A(:)==1)

7 years ago | 0

| accepted

Answered
Binning of data except from histcounts?
A = [0 0 1 1 1 0 0 0 0 NaN NaN 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1]; [U,~,J] = unique(A); inan = find(isnan(U),1,'first');...

7 years ago | 0

Answered
How to generate numbers from probability mass function?
A more generic method: p = [0.2 0.3 0.5]; v = [3 7 10]; n = 10000; c = cumsum([0,p(:).']); c = c/c(end); ...

7 years ago | 1

Answered
How simulate correlated Poisson distributions
One way is to apply <https://en.wikipedia.org/wiki/Poisson_distribution Knuth's Poisson generation> using two <http://comisef.wi...

7 years ago | 0

| accepted

Answered
generate uniformly distributed points inside a hexagon
Here is a generating method without rejection R = 3; centerx = 3; centery = 7; n = 10000; % Generate uniform points in th...

7 years ago | 2

Answered
How to output a mexFunction input without copy
"How do I define an output vector as an input vector which has been modified in a C routine called by the mex function?" You ...

7 years ago | 0

Answered
How to vectorize for loops
x = x(:).'; f = sum(x.^2.*(length(x):-1:1))

7 years ago | 1

| accepted

Answered
I am trying to generate uniformly distributed points inside a hexagon of specific centre (other than the origin). Any help is most welcome, thank you.
Here is a method without rejection: R = 3; centerx = 3; centery = 7; n = 10000; m = 3; X = rand(m-1,n) ....

7 years ago | 1

Answered
What is the complexity of ismember function?
I run this code (R2018b) by changing the length of B is ISMEMBER(A,B), length A fix. It shows clearly the timing is NOT proport...

7 years ago | 0

Answered
interp1 function gives an error ''Error using griddedInterpolant The grid vectors must contain unique points.''
[x,~,J] = unique(z_Sd(:,1)); y = accumarray(J, z_Sd(:,2), [], @mean); vq1 = interp1(x,y,0.3157);

7 years ago | 0

| accepted

Answered
Declaring plot arguments/options beforehand
lineColor = {'k', 'r', 'b', 'm'}; linestyle = {'-'; '--'; ':'; '-.'}; for j = 1:4 options = {'color',lineColo...

7 years ago | 0

| accepted

Answered
How to fill a matrix with numbers from a to b ?
A = 4:2:40

7 years ago | 3

| accepted

Answered
What is the complexity of ismember function?
"Is there a better function in matlab (with lower complexity) that i can use that assuming the input is sorted" You could do ...

7 years ago | 0

Answered
Check if nxm block of 1s is inside binary matrix
[i,j] = find(conv2(MM_bin,ones(3,6),'same')==3*6); I was testing with MM_bin in your MATFILE file which is an 2D array ...

7 years ago | 0

| accepted

Answered
Check if nxm block of 1s is inside binary matrix
[i,j] = find(conv2(MM_bin,ones(3,6),'same')==3*6); will return you all the positions (i,j) with 3*6 submatrix of ones cente...

7 years ago | 0

Answered
mixing randomly existing values in a vector
>> a=[1 1 1 1 1 1 0 0 0 0]; >> r = a(randperm(length(a))) r = 1 1 0 1 0 1 0 ...

7 years ago | 0

| accepted

Load more