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일

0 개 추천

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

Austin Sowers
Austin Sowers 2019년 5월 1일
편집: Austin Sowers 2019년 5월 1일
CA = {[5 -10 2],[6 6 8],[0 9 -10 8 -10 3]};
CB = {[4 17 2],[6 6 10],[9 3 4 9 7 6]};
CC = {[1 2 4],[4 2 1],[1 7 3 1 2 2]};
for i = 1:length(CA)
idx = CA{i}==-10 ;
CB{i}(idx) = CB{i}(idx)+15 ;
end
Perfect! I changed CA and CB a bit and I also added a CC. I have one more question and it should settle my problem.
I would like to add the absolute difference between the adjacent values (i.e. 1 and 4. 7 and 1. 1 and 2) in CC, to the value in CB that matches up with the -10 in CA.
So the first: [4 17 2], should then become: [4 20 2]. By (abs(1-4)) in CC
I hope its not too confusing, but youd help me tons! Thank you!
KSSV
KSSV 2019년 5월 1일
My day is confused......:(
Ok. Sorry about that. Basically, how do I add CC's [1 2 4] ****(4 minus 1)**** to CB's [4 17 2].

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

카테고리

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

제품

릴리스

R2016b

질문:

2019년 5월 1일

댓글:

2019년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by