Help with Matrix plot

9 ビュー (過去 30 日間)
Matrix-Matlab
Matrix-Matlab 2016 年 5 月 7 日
コメント済み: CS Researcher 2016 年 5 月 7 日
Hello, I have these questions that I dont understand how to solve. I have done the first question and managed to create the matrix. But the rest of the questions I don't understand how to do. Can you guys help me with giving pointers on how to solve these?
1. Generate the matrix “Customers” containing random values for the following variables. The matrix must contain 3000 people. ( I have solved this and gotten the matrix) Number 2 is what I have trouble with.
a. Gender. Must be either 1 or 0. 0 signifies that the person is female.
b. Age. Must be between 21 and 85.
c. Insurance risk. Must be a value between 1 and 10.
2. Create a plot that shows the distribution of the insurance risk for males
3. Create a plot that shows the distribution of males and females
4. Calculate the average insurance risk for males, females and combined. The averages must be rounded to two decimals.
I really hope someone can help me out.
Thank you in advance.

回答 (1 件)

CS Researcher
CS Researcher 2016 年 5 月 7 日
Assuming all the values for insurance risk are integers:
A = [randi([0 1],3000,1), randi([21 85],3000,1), randi([1 10],3000,1)];
I will show you how to solve 2. You can then take it further to solve 3 and 4.
%Get all the insurance risk values
insuranceRisks = A(:,3); % Get all values from the third column of A
maleLocs = find(A(:,1)); % Find the 1 values from the first column as those represent males
plot(maleLocs, insuranceRisks(maleLocs));
  2 件のコメント
Matrix-Matlab
Matrix-Matlab 2016 年 5 月 7 日
This is the plot I receive after using your method. Does this look right?
CS Researcher
CS Researcher 2016 年 5 月 7 日
You can use
hist(insuranceRisks(maleLocs))

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

Community Treasure Hunt

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

Start Hunting!

Translated by