フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

2 ビュー (過去 30 日間)
Brandon Overman
Brandon Overman 2016 年 8 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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