MATLAB: Help with if statements

if-statements

If I have a number in one table column, how do I add a new column where the numbers in the second column depend on on the first column. For example, if the first column = 1, new column = 0, if first column = 4, new column = 0.2, if 9, new column = 0.5 etc. I don't want to replace the first column but want to add a second column that is based on the first. I feel I should be using if statements but am new to matlab and I just don't seem to be understanding how to use these yet.
I have attached a table to show how it should look. (The actual table has about 500,000 rows).
Much appreciated, Wendy

Best Answer

num = xlsread('Crop factor.xls');
input_table = [1, 4, 9];
replacement_table = [0, 0.2, 0.5];
new_column = nan(size(num));
[tf, whichcase] = ismember(num, input_table);
new_column(tf) = replacement_table(whichcase(tf));
This will leave nan for any column that was not matched.