フィルターのクリア

Population age model "randi" distribution

3 ビュー (過去 30 日間)
Pesach Nestlebaum
Pesach Nestlebaum 2022 年 4 月 25 日
回答済み: Umang Pandey 2023 年 10 月 6 日
Does anyone know how I can randomly generate numbers that will be distributed to a population-by-age distribution? I want to be able to input a population number, say 1000, and have it return 1000 random numbers distributed in a curve that looks something like the USA age distribution curve... Please explain all code
Thanks!
  2 件のコメント
Torsten
Torsten 2022 年 4 月 25 日
And where is the US age distribution curve ?
Pesach Nestlebaum
Pesach Nestlebaum 2022 年 4 月 25 日
Something along these lines:
Alternatively, maybe I can assign portions of the randomly generated numbers to specific percentages? For example, I want to assign numbers 40-50 to make up 45% of the generated numbers

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

回答 (1 件)

Umang Pandey
Umang Pandey 2023 年 10 月 6 日
Hi Pesach,
As per my understanding it appears that you are trying to generate random numbers from any desired distribution, in your case "The US Age distribution curve".
Here’s an example that can be followed:
% Assuming some Example Data
age_groups = 0:100; % Age groups
population = rand(1, 101); % Dummy population data
% Normalize the data to get the PDF
pdf = population / sum(population);
% Calculate the CDF
cdf = cumsum(pdf);
% Generate uniform random numbers
N = 1000; % Number of random numbers to generate
u = rand(N, 1);
% Sort the CDF and age_groups
[cdf, idx] = sort(cdf);
age_groups = age_groups(idx);
% Find the corresponding ages using the CDF
random_ages = interp1(cdf, age_groups, u, 'nearest');
To know more about the “interp1” function, you can refer the following documentation:
Best,
Umang

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by