substract a vector from a table in matlab

To subtract a vector just from a table in MATLAB, you can use the following code:

main.m
% sample data
t = table([1; 3; 5], [2; 4; 6], 'VariableNames', {'A', 'B'});
v = [1; 1; 1];

% subtract vector from table
t.A = t.A - v;

% view updated table
disp(t)
166 chars
10 lines

Here, we have a sample table t with two columns - 'A' and 'B'. We also have a vector v which we want to subtract from t.A. We achieve this by simply subtracting v from t.A and storing the result back in t.A. The updated table is then displayed on the command window using the disp() function.

related categories

gistlibby LogSnag