I think that you have the right idea, it is just that your code can probably be simplified in order to make it work the way that you want. You've rightly started off by pre-sizing your output matrix v to be a fixed size given the input cell array, you just want to make sure that you don't overwrite this which is what your code is currently doing. So let's start with that:
function [ v ] = heightconvert( data )
[~,n]=size(data);
v=zeros(2,n);
In the above, we've assumed that data is a cell array of two rows only, and n columns. What we want to do, is to iterate over each column and determine the sex (0 or 1) and convert the height from feet to metres. We can do this as
for k=1:n
% get the sex
sex = data{1,k};
% if male, set the value in v to one
if strcmpi(sex,'m') || strcmpi(sex,'male')
v(1,k) = 1;
end
% get the height as a number
height = str2double(data{2,k});
% convert the height to metres if not NaN
if ~isnan(height)
if height<10
% height is in inches
height = height * 0.3048;
else
% height is in centimetres
height = height / 100;
end
end
% update v
v(2,k) = height;
end
In the above we use strcmpi to ignore case (lower or upper) and compare the sex with just 'm' or 'male'. str2double is used to convert the height strings to numbers. If one of these heights is invalid or blank, then the conversion sets the height variable (automatically) to NaN.
Try the above and see what happens!