R[1;-1] how i write the program in matlab for random selection between 1 and -1
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Malik Shah Zeb Ali
el 2 de En. de 2018
Comentada: Pawel Jastrzebski
el 2 de En. de 2018
need help
0 comentarios
Respuesta aceptada
Más respuestas (2)
Torsten
el 2 de En. de 2018
x = rand;
if x <= 0.5
number = 1;
else
number = -1;
end
Best wishes
Torsten.
0 comentarios
Pawel Jastrzebski
el 2 de En. de 2018
clear all;
clc;
% use 'random function' of your choice
% - rand()
% - randi()
% - randn()
% GENERATES A RANDOM NUMBER IN A RANGE OF -1 TO 1:
r1 = -1+ 2*rand(1);
% GETS THE SIGN OF THE 'r1'
sVal = sign(r1);
% ALL ABOVE CAN BE DONE IN ONE LINE:
sVal1 = sign(-1+ 2*rand(1));
2 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!