for a vector, every four data get an average ,then put them into a new vector , its length will be the old's one fourth,how to make it quickly
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Roger
am 6 Jun. 2014
Kommentiert: Star Strider
am 6 Jun. 2014
sometimes it may get average every 5 nums, it will be better to create a function
1 Kommentar
Akzeptierte Antwort
Star Strider
am 6 Jun. 2014
This works:
Data = randn(1,25); % Create Data (# Columns = multiple of 4)
N = 4; % Number to take the means over
Data = Data(1:N*fix(size(Data,2)/N)); % Truncate Data vector if necessary
DataRs = reshape(Data, N, []); % Create NxM matrix
DataRsMean = mean(DataRs,1); % Take column means to create desired result
To get average over 5, change the N = 4 to N = 5.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!