Could someone explain below code
조회 수: 14 (최근 30일)
이전 댓글 표시
I have code like following
for i = 1:rce(2)
for j = 1:rce(1)
if i == 1 & j == 1
mnn(jj,1:4) = [1 rce(1)+2 rce(1)+3 2];
jj = jj + 1;
elseif i ~= 1 & j == 1
mnn(jj,:) = mnn(jj-1,1:4) + 2;
jj = jj + 1;
end
if j > 1
mnn(jj,:) = mnn(jj-1,1:4) + 1;
jj = jj + 1;
end
end
end
Could someone explain below part for me? What is it for
mnn(jj,:) = mnn(jj-1,1:4) + 2;
and
mnn(jj,:) = mnn(jj-1,1:4) + 1;
Best regards
댓글 수: 0
답변 (2개)
Azzi Abdelmalek
2012년 9월 13일
% just trie these to understand
A=[1 2 3;4 5 6;7 8 9]
A(1:2,:)
% 1:2 means line 1 to line 2 ,
% : means all columns
A(:,2:3) %means all lines , and column 2 to column 3
댓글 수: 0
Wayne King
2012년 9월 13일
편집: Wayne King
2012년 9월 13일
Without more context it's hard to say exactly what it's for, but it is simply replacing the jj-th row of mnn with the jj-1 row and adding 2 to each element.
jj must be at least 2 and I'm not sure why they used 1:4 on the RHS because mnn must have only 4 columns.
mnn = randn(4,4);
jj = 2;
mnn(jj,:) = mnn(jj-1,1:4)+2;
You could have just written:
mnn(jj,:) = mnn(jj-1,:)+2;
You should see that the 2nd row is simply the first row with 2 added to each element of the row vector.
The last line simply adds 1.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!