フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

average vector over selected areas

1 回表示 (過去 30 日間)
Lev Mihailov
Lev Mihailov 2020 年 2 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have two vectors, one working, the second sections that I need to average in vector 1
A = randi([5 10],1,548);
B= [102 105 204 99 ]
% what i need to do x=mean(A(1:B(1)) ; x=mean(A(B(1):B(2))
how do i do this?

回答 (1 件)

KSSV
KSSV 2020 年 2 月 3 日
編集済み: KSSV 2020 年 2 月 4 日
A = randi([5 10],1,548);
B= [1 102 105 204]
% what i need to do x=mean(A(1:B(1)) ; x=mean(A(B(1):B(2))
iwant = zeros(length(B)-1,1) ;
for i = 1:length(B)-1
if B(i) < B(i+1) ;
iwant(i) = mean(A(B(i):B(i+1))) ;
else
iwant(i) = mean(A(B(i):-1:B(i+1))) ;
end
end
  3 件のコメント
Image Analyst
Image Analyst 2020 年 2 月 3 日
編集済み: Image Analyst 2020 年 2 月 4 日
Lev, what indexes in A do you want to average if B(i+1) is LESS than B(i)? Like 200 to 5, or 104 to 6? Do you want to take the mean of from 5 to 200 (the opposite order), inclusive? In other words, sort the numbers in ascending order first?
KSSV
KSSV 2020 年 2 月 4 日
Edied the answer.

製品

Community Treasure Hunt

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

Start Hunting!

Translated by