Subtract constant from each element of a cell array

Hello,
How can I subtract a constant from each element of a cell array.
eg
cellArray = { 6.4257 12.6100 12.8211 13.6714 15.8083 11.5896 8.4324 9.8280} { 13.4012 16.2796 8.8723 10.8358 10.8071 10.2066 5.1739}
I would like to subtract 9.8 from each of the values
I tried this but its but the function expects 9.8 to be a cell array of the same length
No_Grav = cellfun(@minus, cellArray , 9.8,'UniformOutput',false)
Thanks in advance

 채택된 답변

madhan ravi
madhan ravi 2020년 8월 24일
편집: madhan ravi 2020년 8월 24일
No_Grav = cellfun(@(x) x - 9.8, cellArray, 'un', 0)

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 8월 24일
Or:
No_Grav = cellfun(@minus, cellArray , repmat({9.8}, size(cellArray)), 'un', 0)

댓글 수: 2

How to subtract each cell mean value from each element for the entire cell array instead of a constant value.
No_Grav = cellfun(@(C) C - mean(C), cellArray, 'uniform', 0);

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

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2020년 8월 24일

댓글:

2021년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by