MATLAB: How to replace string values in a column of a table into numeric

table

I have a table X
It has a column named 'fruit' with string values such as {'apple','orange','grapes'}, There are 13 different string values in the column 'fruit'
Now I need to change it as if apple or orange then 1, grapes then 2 and so on.
How can I do that?

Best Answer

fruit_types = {'apple', 'orange', 'grape', 'banana', 'kumquat', 'peach', 'tomato', 'strawberry', 'pineapple', 'kiwi', 'blueberry', 'durian', 'avacodo'};
fruit_value = [ 1, 1, 2, -4, 5.3, 1 3 5.3, 11, 2, -5.3, 1, 4];
[wasfound, idx] = ismember(X.fruit, fruit_types);
f_values = nan(length(idx), 1));
f_values(wasfound) = fruit_value(idx(wasfound));
X.fruit_value = f_values;