Filter löschen
Filter löschen

Computing the average across columns, while discounting a specific column

1 Ansicht (letzte 30 Tage)
What is the best way to compute the simple average across the columns of a matrix, when one of the columns must be completely discounted?

Antworten (2)

Stephen23
Stephen23 am 13 Okt. 2018
Say you have a matrix M and you want to get the mean of each row, ignoring the third column:
N = 3; % column to ignore
mean(M(:,[1:N-1,N+1:end]),2)

madhan ravi
madhan ravi am 13 Okt. 2018
Bearbeitet: madhan ravi am 13 Okt. 2018
Not sure what you mean but a guess:
x=rand(4)
x(:,2)=[] %removes second column
mean(x,1)
  2 Kommentare
Image Analyst
Image Analyst am 13 Okt. 2018
This changes x, while Stephen's code doesn't change the matrix. Your code also gets the mean along rows (down rows in each column) instead of "across columns", though I'll admit it might be a bit ambiguous what "across columns" actually means.
madhan ravi
madhan ravi am 13 Okt. 2018
ok @sir Image Analyst I was thinking to remove my answer anyway thank you for pointing the error :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by