I have two random numbers and add them together.
a_x = (-2.5 + (2.5+2.5)*rand(1,1));
a = 5*1e-9;
b = 0;
a_z = a.*randn(1,1) + b;
A = a_x + a_z
Step 1:
Now I want to do this 100 times and create the histogram of all the results of A.
Step2:
Then I want to sort the values in ascending order.
Can someone please explain me how to do the two steps?

댓글 수: 5

Ankit
Ankit 2022년 1월 31일
but in above problem, you forgot to mentioned about a_y and Z1
Step 1: using for loop
Lucas Kellermann
Lucas Kellermann 2022년 1월 31일
Sorry I changed it
Arif Hoq
Arif Hoq 2022년 1월 31일
What is Z1?
Lucas Kellermann
Lucas Kellermann 2022년 1월 31일
It is fixed now, sorry
Step 1: using for loop:
a = 5*1e-9;
b = 0;
a_x = zeros(100,1);
a_z = zeros(100,1);
A = zeros(100,1);
for i= 1:100
a_x(i) = (-2.5 + (2.5+2.5)*rand(1,1));
a_z(i) = a.*randn(1,1) + b;
A(i) = a_x(i) + a_z(i);
end
histogram(A)
Step 2: try by yourself :)

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

 채택된 답변

KSSV
KSSV 2022년 1월 31일

0 개 추천

You can achieved the same without using loop.
n = 100 ;
a_x = (-2.5 + (2.5+2.5)*rand(n,1));
a = 5*1e-9;
b = 0;
a_z = a.*randn(1,1) + b;
A = a_x + a_z ;
histogram(A)
To sort the values, you can use function sort. Read about it.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

질문:

2022년 1월 31일

답변:

2022년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by