Non-integer values inside "Randi" function

inputRvector = 'Input r vector for roots of the polynomial as a vector ';
R = input(inputRvector)
R_length = length(R);
input_lower_e_range = 'Input lower range of e ';
e_min = input(input_lower_e_range)
input_upper_e_range = 'Input upper range of e ';
e_max = input(input_upper_e_range)
random_perturbations = randi([e_min e_max],1,R_length);
Hey guys, I am trying to get an input from the user and use that input inside the 'randi' function as a range of vlaues and a length of the 'randi' vector. The trick is that I want values much lower than 1 in the range of (10^-1,10^-8) and I think randi doesnt work with non-integers. Got any ways to do the same except with non-integer values as in the range (10^-1,10^-8)?
I am trying to do as in this case:
r = randi([10 50],1,5)
r = 1×5
43 47 15 47 35
P.S: I have been looking for similar questions for 4 hours and could'nt find anything
Thank you in advance

4 件のコメント

Giuseppe Inghilterra
Giuseppe Inghilterra 2020 年 2 月 16 日
Last line of your code seems to be wrong.
It should be:
random_perturbations = randi([e_min e_max],1,R);
In this way you generate random integer vector of size [1,R] with values within the range [e_min, e_max].
Problem solved?
khalid alharthi
khalid alharthi 2020 年 2 月 16 日
No, it gives me this
Error using randi
Size inputs must be scalar.
Walter Roberson
Walter Roberson 2020 年 2 月 16 日
What values are you entering for the prompts?
Are you entering a vector for the lower bounds and upper bounds?
khalid alharthi
khalid alharthi 2020 年 2 月 16 日
編集済み: khalid alharthi 2020 年 2 月 17 日
I have also solved this problem.
The problem I am having now, is that randi only except integers and I need a way to have values like 10^-5.

サインインしてコメントする。

回答 (2 件)

Steven Lord
Steven Lord 2020 年 2 月 17 日

1 投票

If you want uniformly distributed random numbers that are not integers, randi is not the right tool for the job. See the examples in the documentation for the rand function.
Walter Roberson
Walter Roberson 2020 年 2 月 16 日

0 投票

random_perturbations = randi([e_min e_max],1,R);]
That ] should not be there at the end of the line.

1 件のコメント

khalid alharthi
khalid alharthi 2020 年 2 月 16 日
編集済み: khalid alharthi 2020 年 2 月 17 日
So sorry Mr. Roberson about that a was a typo and It wasnt the problem I had.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2020 年 2 月 16 日

編集済み:

2020 年 2 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by