Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

2 visualizaciones (últimos 30 días)
Brandon Overman
Brandon Overman el 7 de Ag. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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 comentarios
John BG
John BG el 8 de Ag. de 2016
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 el 8 de Ag. de 2016
Using two separate randperm is selection with replacement. Using one randperm would be selection without replacement.
For selection with replacement you could use randi()

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Ag. de 2016
Editada: Azzi Abdelmalek el 7 de Ag. de 2016
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 comentarios
Brandon Overman
Brandon Overman el 7 de Ag. de 2016
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 el 7 de Ag. de 2016
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

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by