Question: In Matlab Code: heightconvert Consider a cell of strings containing gender and height information of some patients ( but the data is a little bit
In Matlab Code: heightconvert
Consider a cell of strings containing gender and height information of some patients but the data is a little bit messy Gender is given as f'female',m or 'male' and heights are given in feet or centimeter some data point are missing For example
fmf 'female' 'male'; ;
Write a function mheightconvertdata to convert the cell array data to a matrix of double m Use to represent female, to represent male. And convert height into meters and represent any missing data points as NaN. Assume that any height value that is less than is in feet and you need the convert those values to meters using foot meter. Use strdouble function to convert a string to a number.
datafmf 'female' 'male'; ; heightconvertdata ans NaN
Pseudocode
You can solve this problem with or without for loops. The following pseudocode describes a solution using for loops:
Initialize m to be a matrix of zeros. Let's process first row of data. For each column of data, Let v be the element on the first row of that column. If v is m or 'male', store a in the corresponding location of m Now let's process second row of data. For each column of data, Let v be the element on the second row of that column. Use strdouble to convert the string v into a numeric value. If the number is less than convert feet into meters. Otherwise, convert centimeters to meters. Store the value in the corresponding location of m
In the first for loop, you don't really need to check for f or 'female', because m already contains zeros. You only need to find m or 'male' and change those to
When checking whether a string v is m or 'male', you should not really use the operator. For example, the expression v'male' will raise an error when v contains 'female', because you'd be comparing vectors of different lengths. Instead of the operator, you need to use the strcmpab function, which will perform lengthchecks for you and will return a true only when a and b are of the same lengths and all of their characters are the same. So strcmpvm will tell you whether v is exactly m; and strcmpv'male' will tell you whether v is exactly 'male'.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
