Matlab Programming, BMI.csv pasted below- BMI is calculated as a person\'s weigh
ID: 3708139 • Letter: M
Question
Matlab Programming, BMI.csv pasted below-
BMI is calculated as a person's weight (in pounds) times 703, divided by the square of the person's heigh (in inches). A BMI in the range 19-25, inclusive, is considered health. Write a program that calculates a person's BMI and prints a message telling whether they are above, within, or below the healthy range. This program should take the file bmi.csv as input, and print the results back out to a table. A new file should be output as jhed_bmi.csv with columns added for the calculated BMI and "obese", "healthy", "underweight". Note - USE STRUCTS to manipulate the data
2b. Generate a plot of weight vs. height from the BMI.csv file with weight on the x axis and height on the y axis. Color code using gender. Draw dotted lines indicating the cutoff between underweight, healthy and overweight. Set the transparency of the points to 0.5 (alpha) so that the plot is legible.
2c. Generate histogram of bmi values (use histogram), plotting separately for male and female gender.
2d. Add a normal distribution as a line plot to the plot, using the mean as mu and standard devication as sigma for the normal distribution. Use makedist (from statistics toolbox) as: makedist('Normal', mu, sigma). Then evaluate it at bin values of histograms (these can be output by histcounts), using pdf as: pdf(pd, x). Rescale the gaussian to the right y range using using the max of the histogram (again from histcounts) vs the max of the normal distribution as the amplitude.
Gender Height Weight Male 73.84702 241.8936 Male 68.7819 162.3105 Male 74.11011 212.7409 Male 71.73098 220.0425 Male 69.8818 206.3498 Male 67.25302 152.2122 Male 68.78508 183.9279 Male 68.34852 167.9711 Male 67.01895 175.9294 Male 63.45649 156.3997 Male 71.19538 186.6049 Male 71.64081 213.7412 Male 64.76633 167.1275 Male 69.28307 189.4462 Male 69.24373 186.4342 Male 67.64562 172.1869 Male 72.41832 196.0285 Male 63.97433 172.8835 Male 69.64006 185.984 Male 67.936 182.4266 Male 67.91505 174.1159 Male 69.43944 197.7314 Male 66.14913 149.1736 Male 75.20597 228.7618 Male 67.8932 162.0067 Male 68.14403 192.344 Male 69.08963 184.4352 Male 72.80084 206.8282 Male 67.42124 175.2139 Male 68.49642 154.3426 Male 68.61811 187.5068 Male 74.03381 212.9102 Male 71.52822 195.0322 Male 69.18016 205.1836 Male 69.5772 204.1641 Male 70.40093 192.9035 Male 69.07617 197.4882 Male 67.19352 183.811 Male 65.80732 163.8518 Male 64.30419 163.108 Male 67.97434 172.1356 Male 72.18943 194.0454 Male 65.27035 168.6177 Male 66.09018 161.1934 Male 67.51032 164.6603 Male 70.10479 188.9223 Male 68.25184 187.0606 Male 72.17271 209.0709 Male 69.17986 192.0143 Male 72.87036 211.3425 Male 64.78258 165.6116 Male 70.18355 201.0719 Male 68.49145 173.424 Male 67.33083 181.4077 Male 66.99094 169.7377 Male 66.49955 163.3095 Male 68.35306 189.7102 Male 70.77446 192.1248 Male 71.21592 198.1985 Male 70.01337 209.5265 Male 71.40318 198.7598 Male 69.55201 198.0795 Male 73.81853 195.2906 Male 66.99688 164.9433 Male 71.41847 179.8639 Male 65.2793 155.2504 Male 68.27419 184.5194 Male 72.76537 220.678 Male 68.09938 183.3127 Male 68.89671 196.4513 Male 69.28951 184.5956 Male 70.52322 207.5328 Male 69.66373 177.2009 Male 67.59527 163.108 Male 72.50812 216.2182 Male 71.25299 204.6555 Male 71.80919 200.9206 Male 72.24517 220.9018 Male 66.51263 196.4499 Male 66.02903 168.6408 Male 67.57715 181.4327 Male 68.24657 198.6587 Male 73.82613 237.9167 Male 69.80246 173.0413 Male 65.95958 160.6839 Male 71.07902 188.6029 Male 66.5962 208.3457 Male 68.95154 193.4351 Male 68.24446 174.1097 Male 72.31683 197.3686 Male 71.81542 201.6207 Male 65.23705 181.012 Male 70.64053 182.1225 Male 64.73193 177.5493 Male 67.10355 164.9746 Male 65.11748 165.7171 Male 71.70123 193.0942 Male 66.83288 180.6839 Male 66.47128 172.7737 Male 69.41153 177.4706 Male 70.05218 200.8187 Male 66.7436 167.7398 Male 66.27433 154.3956 Male 68.32845 177.9847 Male 70.07589 183.9389 Male 68.73299 179.2048 Male 67.55605 158.568 Male 66.25363 166.5035 Male 69.1822 171.9837 Male 67.6091 174.3642 Male 69.29274 187.7454 Male 68.19068 201.488 Male 71.60709 204.927 Male 69.19686 178.6855 Male 67.26196 164.0144 Male 73.68519 223.27 Male 69.53722 202.9583 Male 68.31156 189.3918 Male 67.73896 178.1706 Male 71.70576 223.2993 Male 63.63226 167.0287 Male 68.7212 180.4687 Male 66.94934 164.4391 Male 62.70699 149.9696 Male 72.25841 192.9103 Male 70.90865 201.884 Male 67.60984 179.868 Male 70.80156 196.4677 Male 69.30477 187.5516 Male 66.2429 171.6932 Male 67.49219 191.6996 Male 65.80625 165.8506 Male 71.44371 185.6627 Male 68.46441 178.2818 Male 63.98792 150.9791 Male 71.0019 209.9293 Male 68.13972 174.1578 Male 68.3954 179.879 Male 68.09622 167.7471 Male 68.14059 183.0447 Male 68.86009 169.5568 Male 66.14885 173.4317 Male 66.20603 180.8896 Male 67.43212 183.5089 Male 69.47111 205.9779 Male 70.51586 183.7598 Male 71.33838 201.9545 Male 71.00194 216.1201 Male 66.20235 159.3903 Male 72.54331 210.3364 Male 67.47935 178.6184 Male 65.35041 146.7398 Male 70.84406 195.937 Male 69.93848 170.1759 Male 64.73982 169.6541 Male 69.3084 198.3787 Male 68.83846 179.9077 Male 61.93732 147.2637 Male 68.59334 176.9843 Male 65.21858 185.4678 Male 64.33365 177.4938 Male 68.74891 169.8275 Male 72.48966 198.5817 Male 67.23393 203.3503 Male 67.2636 193.2177 Male 65.1185 178.1349 Male 66.26282 162.7796 Male 67.70168 159.2865 Male 65.5307 172.1143 Male 69.86897 201.837 Male 68.48188 170.3523 Male 72.21396 205.3898 Male 68.17953 169.7878 Male 71.98121 200.4373 Male 66.06514 178.589 Male 66.65616 168.014 Male 67.59942 177.7664 Male 68.24594 193.2776 Male 64.80862 162.3795 Male 67.49222 183.3838 Male 68.18073 181.0561 Male 69.55338 210.8718 Male 66.40225 165.5685 Male 66.59216 196.1484 Male 71.93589 202.0464 Male 68.28704 170.4136 Male 69.95545 201.9481 Male 71.85113 193.387 Male 65.7555 179.8557 Male 67.03185 156.4899 Male 76.70983 235.0354 Male 72.57112 230.5605 Male 69.7288 203.8957 Male 72.79922 218.2164 Male 72.53935 222.6672 Male 72.29474 208.4749 Male 67.25332 180.7798 Male 75.94446 231.9247 Male 66.31623 170.5939 Male 71.15605 188.2715 Male 71.1922 196.0615 Male 72.19751 214.6036 Male 75.14082 224.1243 Male 64.41153 158.5794 Male 64.73442 166.5011 Male 63.41459 160.1406 Male 67.84867 176.1726 Male 65.93178 174.4853 Male 70.96655 193.9065 Male 67.58075 186.9916 Male 68.58927 173.5958 Male 70.32475 193.3466 Male 72.39448 208.4365 Male 70.82086 206.033 Male 65.9033 172.5752 Male 74.79538 232.6354 Male 67.68092 177.2401 Male 67.15596 175.6467 Male 71.77484 212.6261 Male 64.66523 166.9692 Male 68.12277 196.4144 Male 66.78693 165.4312 Male 66.80585 176.5658 Male 67.88601 174.652 Male 69.17358 195.2375 Male 70.22492 205.6844Explanation / Answer
//The answer to the 2a point as explained below.I have taken two struct for clarity.This is not compiled but will help //in the desining the actual problem.This illustrates reading and wriring of the csv file using the helper engine class
//BodyMassIndex will be used foe reading the csv file and BodyMassIndexWriteCSV to write the csv file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileHelpers;
namespace BMIProject
{
[DelimitedRecord(",")]
[IgnoreEmptyLines()]
[IgnoreFirst()]
public struct BodyMassIndex
{
public String Gender;
//Weight
public double Weight{ get; set; }//Person Weight in pounds
//Description, this attribute will handle the double quotes issue
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public double Height{ get; set; } //IN Inches
}
public struct BodyMassIndexWriteCSV
{
public String Gender;
//Weight
public double Weight{ get; set; }//Person Weight in pounds
//Description, this attribute will handle the double quotes issue
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public double Height{ get; set; } //IN Inches
//Weight
public double BMICalculated{ get; set; }//Person Weight in pounds
//Description, this attribute will handle the double quotes issue
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public String Health{ get; set; } //IN Inches
}
}
private void ReadCSVFile(string fileName)
{
try
{
//file location
string fileName = "C:\temp\BMI.csv";
//create a CSV engine using FileHelpers for your CSV file
var engine = new FileHelperEngine(typeof(BodyMassIndex));
//read the CSV file into your object Arrary
var BMIStruct = (BodyMassIndex[])engine.ReadFile(fileName);
if (BMIStruct .Any())
{
//process your records as per your requirements
foreach (var BMIStruct in BodyMassIndex)
{
//add it to your database, filter them etc
String Gender = BMIStruct.Gender
double Weight = BMIStruct.Weight;
double Height = BMIStruct .Height;
}
}
}
catch (Exception ex)
{
LogException(ex)
}
}
private void WriteCSVFile(List<SomeDataSource> dataSource)
{
try
{
//filehelper object
FileHelperEngine engine = new FileHelperEngine(typeof(BodyMassIndexWriteCsv));
//csv object
List<BodyMassIndex> csv = new List<BodyMassIndex>();
//convert any datasource to csv based object
foreach (var item in dataSource)
{
BodyMassIndexWriteCsv temp = new BodyMassIndexWriteCsv();
temp.Gender = item.Gender
temp.Weight = item.Weight;
temp.Height = item.Height;
temp.BMICalculated = (double) (item.Weight / 703) * ((item.Height) * 2 ) ;
if (temp.BMICalculated < 19 )
temp.Health = "underweight";
else if (temp.BMICalculated > 25 )
temp.Health = "obese";
else
temp.Health = "healthy";
csv.Add(temp);
}
//give file a name and header text
string filename = "MyBMIStatus.csv";
engine.HeaderText = "Gender,Height,Weight,BMI,HealthCondition";
//save file locally
engine.WriteFile(Server.MapPath(filename),csv);
}
catch (Exception ex)
{
LogException(ex);
}
}