Info
此问题已关闭。 请重新打开它进行编辑或回答。
Hello, so far I can't get this to respond correctly
1 次查看(过去 30 天)
显示 更早的评论
Clc;
Clear all;
r1=randperm(2,1);
r2=randperm(2,1);
a=sort(r1);
b=sort(r2);
x=[a,b]
q=[2,1]
If x~=q
Disp(X). %cannot get it to correctly display the numbers of the variable every time it doesn't equal q
Else
Disp('x is equal to q')
End
2 个评论
John BG
2016-8-8
why do you sort a scalar anyway?
r1 and r2 are coin tosses, they are either 'head' or 'tail'
and instead of
r1=randperm(2,1);
r2=randperm(2,1);
why not just
x=randperm(2,2);
Walter Roberson
2016-8-8
Using two separate randperm is selection with replacement. Using one randperm would be selection without replacement.
For selection with replacement you could use randi()
回答(1 个)
Azzi Abdelmalek
2016-8-7
编辑:Azzi Abdelmalek
2016-8-7
Don't use uppercase for Matlab function, It's not Clc but clc and not If but if
clc;
clear
r1=randperm(2,1);
r2=randperm(2,1);
A=sort(r1);
B=sort(r2);
X=[A,B]
q=[2,1]
if X~=q
disp(X) %cannot get it to correctly display the numbers of the variable every time it doesn't equal q
else
Disp('x is equal to q')
end
10 个评论
Azzi Abdelmalek
2016-8-7
clc;
r1=randperm(2,1)
r2=randperm(2,1)
X=[r1,r2];
q=[2,1];
if ~isequal(X,q)
disp(X) %cannot get it to correctly display the numbers of the variable every time it doesn't equal q
else
disp('x is equal to q')
end
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!