# how can i extract A= rand([3.85 9.22],5,1) without getting an error

1 ビュー (過去 30 日間)
Pebetsi Palesa 2022 年 9 月 25 日
コメント済み: Pebetsi Palesa 2022 年 10 月 10 日
how can i extract A= rand([3.85 9.22],5,1) without getting an error

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

### 採用された回答

Walter Roberson 2022 年 9 月 25 日
rand(SIZE) * (UPPER - LOWER) + LOWER

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

### その他の回答 (1 件)

Image Analyst 2022 年 9 月 25 日
rand is not like randi. The first argument is not the min and max of the range you want to draw random numbers from. rand() takes the number of elements you want in each dimension. So if you simply follow the first example in the help you'll get
A= 3.85 + (9.22 - 3.85) * rand(5,1)
A = 5×1
7.3545 8.8124 4.1355 5.3735 8.1923
help rand
RAND Uniformly distributed pseudorandom numbers. R = RAND(N) returns an N-by-N matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval(0,1). RAND(M,N) or RAND([M,N]) returns an M-by-N matrix. RAND(M,N,P,...) or RAND([M,N,P,...]) returns an M-by-N-by-P-by-... array. RAND returns a scalar. RAND(SIZE(A)) returns an array the same size as A. Note: The size inputs M, N, P, ... should be nonnegative integers. Negative integers are treated as 0. R = RAND(..., CLASSNAME) returns an array of uniform values of the specified class. CLASSNAME can be 'double' or 'single'. R = RAND(..., 'like', Y) is an array of uniform values with the same data type and complexity (real or complex) as the numeric variable Y. The sequence of numbers produced by RAND is determined by the settings of the uniform random number generator that underlies RAND, RANDI, and RANDN. Control that shared random number generator using RNG. Examples: Example 1: Generate values from the uniform distribution on the interval (a, b). r = a + (b-a).*rand(100,1); Example 2: Use the RANDI function, instead of RAND, to generate integer values from the uniform distribution on the set 1:100. r = randi(100,1,5); Example 3: Reset the random number generator used by RAND, RANDI, and RANDN to its default startup settings, so that RAND produces the same random numbers as if you restarted MATLAB. rng('default') rand(1,5) Example 4: Save the settings for the random number generator used by RAND, RANDI, and RANDN, generate 5 values from RAND, restore the settings, and repeat those values. s = rng u1 = rand(1,5) rng(s); u2 = rand(1,5) % contains exactly the same values as u1 Example 5: Reinitialize the random number generator used by RAND, RANDI, and RANDN with a seed based on the current time. RAND will return different values each time you do this. NOTE: It is usually not necessary to do this more than once per MATLAB session. rng('shuffle'); rand(1,5) See Replace Discouraged Syntaxes of rand and randn to use RNG to replace RAND with the 'seed', 'state', or 'twister' inputs. See also RANDI, RANDN, RNG, RANDSTREAM, RANDSTREAM/RAND, SPRAND, SPRANDN, RANDPERM. Documentation for rand doc rand Other uses of rand codistributed/rand distributed/rand qrandstream/rand codistributor1d/rand gpuArray/rand RandStream/rand codistributor2dbc/rand matlab/rand
##### 1 件のコメント表示非表示 なし
Pebetsi Palesa 2022 年 10 月 10 日
Thank you.

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

### カテゴリ

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by