MATLAB Answers

extract numbers from cell array and calculate mean

조회 수: 4(최근 30일)
JB
JB 30 Apr 2018
Commented: Jan 1 May 2018
I have a cell array containing numbers and strings. Can someone help me with a code that can calculate the mean of the numbers in each row?
Mix = {
'U' [4.7506e+05] [5.0141e+05] [5.4067e+05] [ 542976] [5.7124e+05]
[3.9810e+05] [4.4926e+05] 'U' [ 531440] [5.3655e+05] 'O'
[3.0915e+05] [3.6336e+05] [3.7107e+05] [3.8252e+05] [3.3988e+05] [4.3384e+05]
'U' 'U' 'U' 'O' 'U' [3.7107e+05]
'U' [3.7107e+05] 'U' [3.8252e+05] 'U' 'O' }

  댓글 수: 0

로그인 to comment.

채택된 답변

Fangjun Jiang
Fangjun Jiang 30 Apr 2018
index=cellfun(@isnumeric,Mix);
Mix(~index)={0};
mean(cell2mat(Mix),2)

  댓글 수: 2

JB
JB 30 Apr 2018
Thanks a lot Fangjun, that is perfect
Jan
Jan 1 May 2018
+1. I've overseen that the means are wanted for each row.

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그

제품


Translated by