calculate means to plot

i have many datas.
thething = {26*7 double} {200*7 double} {100*7 double} .... {22*7 double}.
I want to call out each mean in (:,4) to form a plot. however the matlab keep saying the means after 22th cell do not exist. This is the script i use.
>> mean(cellfun(@(x) x(:,4), thething,'UniformOutput',false))
But it could not generate anything.

7 件のコメント

Kuang-Yu WANG
Kuang-Yu WANG 2018 年 6 月 26 日
sorry guys what I mean is that I need to get the mean of (1,4) (2,4)...(n,4) to form a plot
Walter Roberson
Walter Roberson 2018 年 6 月 26 日
That is what the code I suggest calculates, the mean of those items, producing one numeric output for each entry in thething
Kuang-Yu WANG
Kuang-Yu WANG 2018 年 6 月 26 日
But the result after i enter the code generate less cells than i want. The result should be (mean of all (1,4) in all matrix) (mean of all (2,4) in all matrix).....However ur code seems to give me (mean of 1st matrix) (mean of 2nd matrix)....
Walter Roberson
Walter Roberson 2018 年 6 月 26 日
When should your code stop? You show an entry with 22*7 so if you tried to go beyond (22,4) then you would run out of data in that last entry. How do you want to handle that? Are you wanting to take the mean only of the entries that do have data?
Kuang-Yu WANG
Kuang-Yu WANG 2018 年 6 月 26 日
yes!! Just ignore the cells do not have data. But I could not find away to do
Walter Roberson
Walter Roberson 2018 年 6 月 26 日
Do not do it with cellfun: do it with a loop.
It is possible to do with cellfun, but you end up having to pad short arrays with nan and then using nanmean. I do not recommend the technique for beginners.
Kuang-Yu WANG
Kuang-Yu WANG 2018 年 6 月 26 日
Thanks for suggestion. But I still do not find a simple way for loop to do the task.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 6 月 26 日

0 投票

cellfun(@(x) mean(x(:,4)), thething)
KSSV
KSSV 2018 年 6 月 26 日

0 投票

N = [10 8 4 5 9] ;
M = length(N) ;
A = cell(M,1) ;
% create some radom data
for i = 1:M
A{i} = rand(N(i)) ;
end
% get mean
C = cellfun(@(x) mean(x(:,4), 1), A, 'UniformOutput', false);

カテゴリ

製品

質問済み:

2018 年 6 月 26 日

コメント済み:

2018 年 6 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by