Info

此问题已关闭。 请重新打开它进行编辑或回答。

Hello, so far I can't get this to respond correctly

2 次查看(过去 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
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
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
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 个评论
Brandon Overman
Brandon Overman 2016-8-7
Still fails, I have what you say always works now every time it says x is equal to q when that is not true if r2 is equal to 2 than x would be 2,2 so not equal to q
Azzi Abdelmalek
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!

Translated by