Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Averaging Every nth column but the interval is different every time?

1 visualización (últimos 30 días)
Shyam Patel
Shyam Patel el 30 de Mayo de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
So I have coulmn vector of numbers 249 numbers long. The numbers go like this:
The problem is to average the numbers that are similar (delta = 1.5), i.e. points 1-8, 9-16, etc. The issue is that most of the points have 8 values, but some of them do not, so my previous code:
avg = mean(reshape(run,8,[]))';
does not work since the interval is 8, but actually the interval is not always 8 (example points 17-23 which is only 7 points). How would I go about averaging this data set at each of the points?

Respuestas (2)

Star Strider
Star Strider el 30 de Mayo de 2019
If your data do not have uniform ranges, a loop is likely the only option:
V = [ones(4,1)+rand(4,1)/50; ones(6,1)*4+rand(6,1)/50; ones(8,1)*8+rand(8,1)/50]; % Create Data
idx = [1; find(diff([0;V])>2); numel(V)]; % Index Changes
for k = 1:numel(idx)-1
meanV(k) = mean(V(idx(k):idx(k+1))); % Mean Of Index Range
end
It would be easier with your data, since the uniquetol function could be applicable, allowing the use of the accumarray function. Without your data, and seeing only the image of it you posted, it seems safest to use the find function and the loop.

Matt J
Matt J el 30 de Mayo de 2019
[~,~,G]=unique(floor(run));
avg=splitapply(@mean,run,G)

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by