How can I write y0 code in one line and still I can get this output.

조회 수: 1 (최근 30일)
SAHIL SAHOO
SAHIL SAHOO 2023년 5월 2일
댓글: VBBV 2023년 5월 3일
y0= [ (1e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(1e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(1e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1)); ]
================================================
output
y0 = 0.0016
0.0079
0.6824
0.0017
0.0060
1.2281
0.0069
0.0075
-1.1515

답변 (1개)

VBBV
VBBV 2023년 5월 2일
y0= [ (1e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(1e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(1e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1)); ]
y0 = 9×1
0.0082 0.0023 -0.4870 0.0071 0.0082 1.1632 0.0008 0.0039 1.7553
y0 = [1e-2*rand(6,1);repmat((-3.14)*rand(1)+(3.14)*rand(1),3,1)]
y0 = 9×1
0.0018 0.0012 0.0068 0.0078 0.0044 0.0079 -1.7388 -1.7388 -1.7388
  댓글 수: 3
SAHIL SAHOO
SAHIL SAHOO 2023년 5월 3일
Here I'm having same problem that you have, the first two no.
0.0031
0.0010
0.8000
0.0083
0.0089
1.8618
0.0020
0.0010
1.6583
are less than 0.0031 but the 3rd no. is between -3.14 to 3.14,
therefore I want to modify my code in such manner that I can satisfy my given condition.
VBBV
VBBV 2023년 5월 3일
how is it less than 0.0031 ? take a look at the values, they are just randome values multiplied by 1e-2. if you want the first two values to higher than 0.0031, then you can use randi instead of rand
y0 = [ 0.0096
0.0081
0.0060
0.0044
0.0098
0.0030
-0.3596
-0.0365
-0.3486]
y0 = 9×1
0.0096 0.0081 0.0060 0.0044 0.0098 0.0030 -0.3596 -0.0365 -0.3486
y0 = [1e-2*randi([0 10],6,1);[(-3.14)*rand(1)+(3.14)*rand(1)].*rand(3,1)]
y0 = 9×1
0.0700 0.1000 0.0500 0.0600 0.0600 0.0700 -0.2265 -0.4150 -0.3119

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by