How can I use 'while' ??
이전 댓글 표시
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
Stephen23
2017년 12월 9일
"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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!