필터 지우기
필터 지우기

Help with Matrix plot

조회 수: 1 (최근 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))

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

카테고리

Help CenterFile Exchange에서 Signal Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by