I want to find the average of a matrix from excel in MATLAB

12 ビュー (過去 30 日間)
Alexandra Brian
Alexandra Brian 2017 年 3 月 6 日
コメント済み: Alexandra Brian 2017 年 3 月 6 日
Hi,
I would like to find the average of the matrix found in the spreadsheet attached in MATLAB. I calculated my results manually, but would like to find it through MATLAB. I wrote the following code, but was returned an incorrect value:
sheet = 1;
xlRange = 'A1:E7449';
Data = xlsread('data.xlsx', sheet, xlRange);
AvgData= mean(Data);
I received the following output:
NaN 0.0874718684775714 NaN NaN NaN
However, the output should be:
0.094422821
I would also like to know if there's a way to find data that is repeated in each column and record it.

採用された回答

the cyclist
the cyclist 2017 年 3 月 6 日
編集済み: the cyclist 2017 年 3 月 6 日
nanmean(Data(:))
will do what you want.
You need nanmean rather than mean, because Data has NaN values in it, due to the columns being different lengths.
You need Data(:) rather than Data, because you want the mean of all the values as one vector, rather than the means of each column.
You should be able to use the unique command to find the repeated data elements.

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 3 月 6 日
You can use mean() with the 'omitnan' option, and the : (colon) operator (otherwise you get column means instead of the mean of the whole thing), like this
theMean = mean(Data(:), 'omitnan');
Regarding repeats, if a data value is in both row 2 and row 7, is it "repeated" or does it need to be in the adjacent row to be repeated?
  1 件のコメント
Alexandra Brian
Alexandra Brian 2017 年 3 月 6 日
If a data value is in both row 2 and row 7, it is "repeated." It does not need to be in the adjacent row to be repeated.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by