Plotting a digital polymer chain.
Mostra commenti meno recenti
I got the instructions from my professor and have no idea how to complete the code. The A beads should be red and the B beads should be blue.
1) Create two empty 30 x 2 matrices; one matrix for A beads, the other for B beads.
2) Open a for loop from index i=1:30
3) Calculate a random number
4) If the random number is <=0.5, then for the A matrix, change the i,1 element to the current index in the for loop, and the i,2 element to a value of 1.
If the random number is >0.5, then for the B matrix, change the i,1 element to the current index in the for loop, and the i,2 element to a value of 1.
5) Repeat steps 3 and 4 all the way up to i = 30
6) Close the for loop
7) Remove all the zero rows from the A and B matrices
8) Plot the beads
1 Commento
darova
il 15 Mar 2021
Please show your attempts
Risposte (1)
Sydney Carrow
il 15 Mar 2021
0 voti
7 Commenti
darova
il 15 Mar 2021
You are in a terrible situation. What can i do for you?
Sydney Carrow
il 15 Mar 2021
darova
il 16 Mar 2021
Here you go
A = zeros(30,2);
B = zeros(30,2);
for i = 1:30
num = rand;
if num < 0.5
A(i,1) = num;
end
end
Sydney Carrow
il 16 Mar 2021
darova
il 17 Mar 2021
Current index is "i"
Sydney Carrow
il 17 Mar 2021
Modificato: darova
il 18 Mar 2021
darova
il 18 Mar 2021
Here are some corrections
You don't need to check A(i,1)==i part
if A(i,1)==i || rand<=0.5
You don't need red square part (it's the same as above)

Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!