R[1;-1] how i write the program in matlab for random selection between 1 and -1
1 次查看(过去 30 天)
显示 更早的评论
need help
0 个评论
采纳的回答
更多回答(2 个)
Pawel Jastrzebski
2018-1-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!