please help with multiplication and division function

조회 수: 4 (최근 30일)
Emmanuel Akpan
Emmanuel Akpan 2018년 7월 4일
댓글: Robert U 2018년 7월 4일
A={1;2;3;4;5;6;7}; B={1;2;3;4;5;6;7};
A and B are both cell arrays, I would like to find C
C=(3*A-C)/2;

답변 (2개)

Stephen23
Stephen23 2018년 7월 4일
편집: Stephen23 2018년 7월 4일
The solution is simple: don't use cell arrays:
A = [1;2;3;4;5;6;7];
B = [1;2;3;4;5;6;7];
C = (3*A-B)./2;

Robert U
Robert U 2018년 7월 4일
편집: Robert U 2018년 7월 4일
Hi Emmanuel Akpan,
The question you raised is not clear. Taking into consideration the given equation you can find easily by manual calculation that it is satisfied for
C = A;
In case you would like to calculate
C = (3*A-B)/2;
while use of cell arrays is mandatory, there are several ways of doing that. Depending on what output format you would like to achieve you might have to alter the shown examples. I assume, output should be cell array again:
A={1;2;3;4;5;6;7};
B={1;2;3;4;5;6;7};
C1 = cellfun(@(cA,cB) (3*cA-cB)/2,A,B,'UniformOutput',false);
C2 = arrayfun(@(dIn) dIn,(3*cell2mat(A)-cell2mat(B))/2,'UniformOutput',false);
Kind regards,
Robert
  댓글 수: 2
Stephen23
Stephen23 2018년 7월 4일
편집: Stephen23 2018년 7월 4일
Note that instead of this:
C2 = arrayfun(@(dIn) dIn, ... ,'UniformOutput',false)
to place the elements of a numeric array into the cells of a cell array, just use num2cell:
C2 = num2cell(...)
Robert U
Robert U 2018년 7월 4일
True, Thank you Stephen.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by