Find the average for a matrix excluding data in the first column

조회 수: 5 (최근 30일)
Sarah White
Sarah White 2020년 5월 11일
답변: Image Analyst 2020년 5월 11일
I have a 20x6 matrix and I want to find the average value of the entire range of values (sensor data) but not including the first column (time values) - how can I do this?
This gives me 5 averages (one for each of the sensor data columns).
Totalave=mean(SENSOR(:,2:6))
Thanks in advance

답변 (2개)

Johannes Hougaard
Johannes Hougaard 2020년 5월 11일
You could simply add another mean around it:
totalave = mean(mean(sensor(:,2:6)));
Or you could introduce a temporary variable (e.g. sensor_data) and use the (:) operator to create a column vector rather than an n-by-m matrix
sensor_data = SENSOR(:,2:end);
Totalave=mean(sensor_data(:));

Image Analyst
Image Analyst 2020년 5월 11일
If you have the Image Processing Toolbox, simply use mean2() instead of mean():
Totalave = mean2(SENSOR(:, 2 : 6))

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by