Multiple selection of an array

4 ビュー (過去 30 日間)
Patrick Nijkamp
Patrick Nijkamp 2020 年 2 月 10 日
回答済み: fred ssemwogerere 2020 年 2 月 10 日
Hello everyone,
i have an array of 150.000 rows, and i want to take the means of 300 rows once every 1460 rows. for example mean of row 1100:1400 and mean of row 2560:2860.
M = mean([
flow(1100:1400);
flow(2560:2860);
flow(4020:4320); ])
i have to take 100 means, but i only get 1 output when i use this. flow is the name of the array i use.

採用された回答

fred  ssemwogerere
fred ssemwogerere 2020 年 2 月 10 日
Hello, based on the indexing used in your question, i think something like this could do:
% Assuming your matrix or vector to be: "t", having 150,000 rows
t;
% Assume the starting index for averaging 300 rows at a defined interval to be; "i"
i=1100;
% Set interval over which to average every 300 rows
interval=1460; % interval over which the start of the next 300 rows will be chosen
% Number of rows from your matrix or vector; "t"
nrows=length(t);
% Using a "for" loop
for k=1:ceil(nrows/interval)
if i+300<=nrows % this condition prevents averaging beyond the length of the array
avg_flow(k,1)=mean(t(i:i+300,:));
else
end
i=i+interval;
end
% Please note the length of "avg_flow" will determine the total number of intervals taken for a given starting index.

その他の回答 (2 件)

Star Strider
Star Strider 2020 年 2 月 10 日
Using a simple loop:
Array = rand(150000,1); % Create Array
v = [1100 : 1460 : numel(Array)];
for k = 1:numel(v)
ArrayMean(k) = mean(Array((0:299)+v(k)));
end

Matt J
Matt J 2020 年 2 月 10 日
編集済み: Matt J 2020 年 2 月 10 日
You can use sepblockfun downloadable from here
as follows
M=sepblockfun(flow,[300,inf])

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by