AVERAGE OF EACH COLUMNS IN CELL
Afficher commentaires plus anciens
I have 'data' variable which is cell. I want to take the average of each column in 'data'. How can I take average of column in 'data' and subtract average from the 'data'?
Réponses (2)
Image Analyst
le 28 Avr 2019
Try this (untested):
dataContents = data{1} % Extract array from a cell called data . "data" was NOT called a cell array so I assume it's only one cell.
% Compute averages of columns
columnAverages = mean(dataContents, 1); % Average going down rows within columns.
% Subtract column average from each columns
[rows, columns] = size(dataContents);
% Expland to matrix the same size as the dataContents matrix.
columnAverages = repmat(columnAverages, [rows, 1]); % Legacy way of doing it that should work with older versions.
output = dataContents - columnAverages; % Do the subtraction
2 commentaires
Aybüke Ceren Duran
le 28 Avr 2019
Image Analyst
le 28 Avr 2019
Modifié(e) : Image Analyst
le 28 Avr 2019
Is it possible that you called your m-file "mean.m"? Or you have an array in your code called mean? I think that might cause the error. Otherwise, tell me what data is, or attach it in a mat file with the paper clip icon.
Aybüke Ceren Duran
le 28 Avr 2019
0 votes
1 commentaire
Image Analyst
le 28 Avr 2019
To get the average of each column, use mean() on your matrix M:
averageOfColumns = mean(M, 1);
Catégories
En savoir plus sur Data Types dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!