calculate means to plot

조회 수: 1 (최근 30일)
Kuang-Yu WANG
Kuang-Yu WANG 2018년 6월 26일
댓글: Kuang-Yu WANG 2018년 6월 26일
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
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일
cellfun(@(x) mean(x(:,4)), thething)

KSSV
KSSV 2018년 6월 26일
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);

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by