I have a array of 61 number, i want to take mean of 1st and 17th number, then 2nd and 18th number and then want to put this mean values in a array?

1 次查看(过去 30 天)
I don't want to use loop here.

回答(1 个)

KSSV
KSSV 2021-7-29
A = rand(1,61) ;
idx = [(1:46)' (16:61)'] ; % get indices
iwant = mean(A(idx),2)
  7 个评论
KSSV
KSSV 2021-7-29
A = rand(180,270,61) ;
idx = [(1:46)' (16:61)'] ;
B = zeros(180,270,46,2) ;
B(:,:,:,1) = A(:,:,idx(:,1)) ;
B(:,:,:,2) = A(:,:,idx(:,2)) ;
Check and then use....confirm the result with a loop.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by