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?

Answers (1)

A = rand(1,61) ;
idx = [(1:46)' (16:61)'] ; % get indices
iwant = mean(A(idx),2)

7 Comments

@KSSV thanks. What will be the method if we implement same analogy on a 3d matrix whose 3rd dimension is 61?
I am replacing the third dimension with the idx, but it's giving wrong answer.
I really appreciate your help!
Tell me the dimensions of 3D matrix. What you expect from it.
So you want mean of 1st and17th matrix, so you expect a 3D matrix of size 180*270..is it?
The final matrix will be a 3d matrix.
First layer (or matrix) of 3d output= mean of 1st and 17 th matrix of original 3d data
Second layer of 3d output=mean of 2nd and 18th matrix of original 3d data
....so on. Hope this clarifies more.
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.
@kssv thanks for your help, but this not what I was looking for. I solved it.
Thanks man!

Sign in to comment.

Products

Release

R2020b

Asked:

on 29 Jul 2021

Commented:

on 29 Jul 2021

Community Treasure Hunt

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

Start Hunting!