add to values in a varying size cell array

조회 수: 19 (최근 30일)
Austin Sowers
Austin Sowers 2019년 5월 1일
댓글: Austin Sowers 2019년 5월 1일
I would like to add 15 to the values in CB that match up with the -10s in CA. (i.e. 17, 4, and 7)
CA = {[-10 2],[6 6 8],[0 9 -10 8 -10]};
CB = {[17 2],[6 6 10],[9 3 4 9 7]};
idx = cellfun(@(x)any(x(:)==-10),CA) & not(cellfun(@(x)any(x(:)==-10),CB)); % Not sure if I am on the right track with this.

답변 (1개)

KSSV
KSSV 2019년 5월 1일
CA = {[-10 2],[6 6 8],[0 9 -10 8 -10]};
CB = {[17 2],[6 6 10],[9 3 4 9 7]};
for i = 1:length(CA)
idx = CA{i}==-10 ;
CB{i}(idx) = CB{i}(idx)+15 ;
end
  댓글 수: 3
KSSV
KSSV 2019년 5월 1일
My day is confused......:(
Austin Sowers
Austin Sowers 2019년 5월 1일
Ok. Sorry about that. Basically, how do I add CC's [1 2 4] ****(4 minus 1)**** to CB's [4 17 2].

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by