Manipulating and assigning values to Cell Arrays
조회 수: 18 (최근 30일)
이전 댓글 표시
I am currently dealing with two cell arrays that have the following anatomy 14x1 cell, Each array is of size 63x63[double]. the cell names are 'a1' & 'b1'.
I want to go in each array and then go to each i &j and subtract the first 13 arrays from the last one{14x1}, which means I want to subtract cell {1,1} - {14,1},{2,1} - {14,1},{3,1} - {14,1},.....and so on. At the end I want the result of the form 13x1 cells assigned to 'a' and 'b''. I have the following code but it only gives me the last value after the calculation.
Any help would be appreciated, Thank you in advance.
for i = 1:63
for j = 1:63
a(i,j) = 0;
b(i,j) = 0;
for k = 1:13
a(i,j) = a1{k}(i,j)-a1{end}(i,j);
b(i,j) = b1{k}(i,j)-b1{end}(i,j);
end
end
end
댓글 수: 0
채택된 답변
Rik
2019년 1월 27일
You are overwriting your matrices in every iteration. Also, you don't need those outer loops, since Matlab can do matrix operations in one go.
a=cell(numel(a1)-1,1);
b=cell(numel(b1)-1,1);
for k = 1:numel(a)
a{k} = a1{k}-a1{end};
b{k} = b1{k}-b1{end};
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!