Help with Matrix plot
3 次查看(过去 30 天)
显示 更早的评论
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
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!