Matrix addition in a loop in a random column
Afficher commentaires plus anciens
I have written a code, in which a block of 1x1 gets added to a Matrix of zeros M=zeros(10,10); and shifts the block from round to round one position down. My Problem is, that the Block is fixed in Column 1 but I want it to be in a Random position in Line 1. How can I implement this?
The other Problem is, that I want this block to be bigger than just 1x1. I want it to be 2x2 big. So I guess the code for this is: M(1:2,1:2)=1; but when I just change every Vektor Like M(1)=M(1)+1; to M(1:2,1:2)=M(1:2,1:2)+1 it doesnt work.. so my question is, how can I change these 1x1 blocks to 2x2 blocks, randomly placed in Line 1, so that everything still works?
Y=10;
X=10;
Matrix=zeros(Y,X);
for n=0:6
Matrix(1)=Matrix(1)+1;
for k=2:Y
Test = Matrix(k)+1;
if Test == 1
Matrix(k-1) = 0;
Matrix(k) = 1;
disp(Matrix)
end
end
end
Thank you!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Simulation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!