필터 지우기
필터 지우기

mean of all positives in a cell array

조회 수: 1 (최근 30일)
BoIs
BoIs 2016년 11월 11일
댓글: Hiskiel Stephanus 2016년 11월 11일
I have a cell array where the cells are something like this: [ 92x1 double] [215x1 double] [127x1 double] [120x1 double] [ 89x1 double] ....and so on(1000 odd cells). I want to find the means of the negative and positive elements in these cells individually. I tried :
if true
% code
end
m = (s{i})<0;
m1 =cellfun(@(x) [mean(mean(x(m,:),2))],s,'un',0)
but when I try the same for all positive elements using n = (s{i})>0; it says index exceeds matrix dimension. Any idea of what I may be doing wrong and how I can fix this or any other suggestions? Thanks!
  댓글 수: 1
Hiskiel Stephanus
Hiskiel Stephanus 2016년 11월 11일
Hi
Please find a solution to your problem in the attached Matlab file. You should of course adjust it accordingly to suit your needs.
Regards Hiskiel

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 11월 11일
편집: Andrei Bobrov 2016년 11월 11일
m1 =cellfun(@(x) [mean(x(x<0)),mean(x(x>0))],s,'un',0)
  댓글 수: 5
BoIs
BoIs 2016년 11월 11일
Thankyou both!! that worked!
BoIs
BoIs 2016년 11월 11일
Im new to matlab, just wanted to know how does the ; at the end exactly help with the error? Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by