How can I use 'while' ??
Mostra commenti meno recenti
I got global A, B, C, D, E, F, G, H, I. And they are all 2*1 matrix. And I would like to set random values for them.(Random values are between 2~14 for (1,1) of those matrices, and 1~4 for (1,2) of those matrices.) And also I would like to make all of them different each other.
I tried like this,
A = [ randi([2 14]); (randi(4)) ]
B = [ randi([2 14]); (randi(4)) ]
C = [ randi([2 14]); (randi(4)) ]
D = [ randi([2 14]); (randi(4)) ]
E = [ randi([2 14]); (randi(4)) ]
F = [ randi([2 14]); (randi(4)) ]
G = [ randi([2 14]); (randi(4)) ]
H = [ randi([2 14]); (randi(4)) ]
I = [ randi([2 14]); (randi(4)) ]
while A == B | A == C | A == D | A == E | A == F | A == G | A == H | A == I | B == C | B == D | B == E | B == F | B == G | B == H | B == I | C == D | C == E | C == F | C == G | C == H | C == I | D == E | D == F | G == G | D == H | D == I | E == F | E == G | E == H | E == I | F == G | F == H | F == I | G == H | G == I | H == I
A = [ randi([2 14]); (randi(4)) ]
B = [ randi([2 14]); (randi(4)) ]
C = [ randi([2 14]); (randi(4)) ]
D = [ randi([2 14]); (randi(4)) ]
E = [ randi([2 14]); (randi(4)) ]
F = [ randi([2 14]); (randi(4)) ]
G = [ randi([2 14]); (randi(4)) ]
H = [ randi([2 14]); (randi(4)) ]
I = [ randi([2 14]); (randi(4)) ]
end
But it never stops! Even all matrices(A, B, C, D, E, F, G, H, I) are different each other. What is wrong with this? Help me Plz
1 Commento
Stephen23
il 9 Dic 2017
"I got global A, B, C, D, E, F, G, H, I..."
Do not use global variables. Pass values properly between workspaces to make your code more efficient and much easier to debug. Globals are how people write ugly spaghetti code that is impossible to debug.
Risposta accettata
Più risposte (0)
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!