average of first element of every cell

3 ビュー (過去 30 日間)
Diego Hens
Diego Hens 2020 年 12 月 1 日
コメント済み: Ameer Hamza 2020 年 12 月 1 日
Hello,
I have gotten such a headache trying to solve this one. It shouldn't be that difficult.
I have a table. Every cell has a vector coordinates like this [a b c] (a, b and c are some numbers).
I would like to do the mean of the first, second and third element of the every column. That is, if I have 9 columns I should get 9 vectors with the mean of every column.
I tried like this:
Average_Vector{j,i} = [mean(Vector_per_Point{j,i}(1)),mean(Vector_per_Point{j,i}(2)),mean(Vector_per_Point{j,i}(3))];
Vector_per_Point is the table containing a vector in each cell.
I know this line of code is wrong, as it only makes the mean of a cell. That means that I get the same table as in Vector_per_Point (since the average of only one number is the same number in itself).
The written line of code is in a for loop j=... and this loop is in another for loop i =...
Thank you.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
編集済み: Ameer Hamza 2020 年 12 月 1 日
The exact solution depends on how your data is structured. I guess the following will work
Average_Vector = mat2cell(mean(cell2mat(Vector_per_Point)), 1, 3*ones(size(Vector_per_Point,2),1))
If it does not work, please attach your variable in a .mat file.
  2 件のコメント
Diego Hens
Diego Hens 2020 年 12 月 1 日
Thank you for the quick and correct solution :)
Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
I am glad to be of help! :)

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

その他の回答 (0 件)

カテゴリ

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