Could someone explain below code
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Azzi Abdelmalek
il 13 Set 2012
% 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 Commenti
Wayne King
il 13 Set 2012
Modificato: Wayne King
il 13 Set 2012
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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!