Menu
  • HOME
  • TAGS

expanded accumarray output for unsorted data in matlab

matlab,accumarray

You basically need to replicate the output of accumarray. The replication pattern is given by the third output of unique: [~, ~, k] = unique(id); s = accumarray(k,data); result = s(k); Another possibility: use bsxfun to detect equal values of id, and then matrix multiplication to accumulate the corresponding values...

Vectorization using accumarray

matlab,vectorization,accumulate,accumarray

Given: CylCoorsSample = [263.0000 184.2586 10.0000 264.0000 183.0417 10.0000 264.0000 182.1572 10.0000 82.0000 157.4746 11.0000 80.0000 158.2348 11.0000 86.0000 157.3507 11.0000 84.0000 157.7633 11.0000] PointValuesSample = [0.4745 0.5098 0.5020 0.4784 0.4510 0.4431 0.5804] You can use accumarray as follows (using the third output of unique to generate the required subs...

Matlab - Accumarray confusion?

matlab,accumarray

As described in the docs for accumarray: Considering a call to the function like the following: A = accumarray(subs,val) The values in each row of the m-by-n matrix subs define an n-dimensional subscript into the output, A. Therefore, in your case since subs is a Something x 2 array, each...

Summing rows by index using accumarray

matlab,accumarray

Try this: M_sum = (L + eye(size(L,1)))*M; M_sum = triu(M_sum, 1); M_sum = M_sum + M_sum.'; This works because you already have matrix L, so matrix multiplication can be used to select and sum the rows of M. Using accumarray here would have two drawbacks: You'd need to apply find...

Fast rolling correlation in Matlab

matlab,correlation,accumarray

Following the advice from @knedlsepp, and using filter as in the movingstd, I found the following solution, which is quite fast: function Cor = MovCorr1(Data1,Data2,k) y = zscore(Data2); n = size(y,1); if (n<k) Cor = NaN(n,1); else x = zscore(Data1); x2 = x.^2; y2 = y.^2; xy = x .*...

Stable accumarray in MATLAB

matlab,accumarray,stable-sort

We can use sortrows as a preprocessing step to sort the indices and corresponding values first, as its documentation states: SORTROWS uses a stable version of quicksort. As the subscripts in subs should be sorted with respect to their linear indices, we need to sort them in reverse lexicographic order....

Using percentage function with accumarray

arrays,matlab,percentage,accumarray

This could be one approach: %// make all those non-zero values to zero AprefCORmask = AprefCOR == 1; %// you have done this [OTPCORorder1,~,idx] = unique(OTPCORorder,'stable'); %// Find number of each unique values counts = accumarray(idx,1); %// Find number of ones for each unique value sumVal = accumarray(idx,AprefCORmask); %// find...

Count occurences of strings in column - Matlab

matlab,unique,accumarray

You can use unique with histc - %// Get countries and their occurences [countries,~,id] = unique(cellstr(val),'stable') occurrences = histc(id,1:max(id)) You can then display the number of occurrences against the country names as a table - >> table(countries,occurrences) ans = countries occurrences _________ ___________ 'USA' 3 'France' 2 Display output as...

Setting an Hourly x-Axis to plot Accumarray in Matlab

matlab,graph,plot,accumarray

I guess you just want the x ticks to be spaced by 1 hour, independently of the data spacing? From your example, I don't see that you necessarily have a data point once an hour. If my understanding is correct, try replacing datetick('x','ddd HHPM') with the following: hr_step = 0.0417;...