Loop for extracting a matrix

조회 수: 1 (최근 30일)
Meddour Aissam riad
Meddour Aissam riad 2019년 6월 14일
편집: dpb 2019년 6월 14일
Hi everyone,
I have an array/matrix of two column : acceleration (speed) , it contain 150 values. for each 10 valuies I want my program to calculates the average speed and acceleration of all 10 values ​​(from 0 to 10, then from 10 to 20 ...)
can you help me with a program
  댓글 수: 1
dpb
dpb 2019년 6월 14일
"...calculates the average speed and acceleration of all 10 values ​​(from 0 to 10, then from 10 to 20 ...)"
NB: each of those ranges is acutally 11 elements, not 10...

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillaume
Guillaume 2019년 6월 14일
Reshape your array into a 3D array with rows of 10 elements, columns of 150/10 = 15 elements, and 2 pages. Take the mean across the rows to get a 1x15x2 array which is the mean across ten consecutive values. Squeeze that back into a 15x2 array:
squeeze(mean(reshape(yourarray, 10, [], 2), 1)) %will error if the number of rows is not a multiple of 10

dpb
dpb 2019년 6월 14일
편집: dpb 2019년 6월 14일
nAvg=10;
mnAV=reshape(mean(reshape(av,nAvg,[])),[],2);
Same caveat w/ Guillaume; errors if not divisible by nAvg and the final reshape is based on the input array being specifically two columns. That limitation can be removed by using size(av,2) in place of the hardcoded '2', of course.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by