MATLAB: Subtract values of a row vector to each column of a matrix.

for loopMATLABmatrix manipulationvector

Hello guys,
I have written a small code attempting to remove an offset from a set of signals stored in a matrix. I need to subtract for each value of a column of a matrix (120×10) the value contained in a single row vector (1×10). Basically each column of the matrix represents an independent signal.
I have put together some code but I'm not obtaining what expected.
Here 'data' is a matrix (120×10) whereas 'columnMeans' is a row vector (1×10). Each column of the row vector should be used for the subtraction of the corresponding column of the matrix. I'm not even sure whether for loop is necessary.
for i=1:10
data_new=data-columnMeans(i)
end

Best Answer

Hi, I have attached an example:
columnMeans=randi([1 10],1 ,10);
data=randi([1 30],120,10);
[m,n] = size(data);
for i=1:m
data_new(i:i,:)=data(i:i,:)-columnMeans(:,:)
end
data_new
size(data_new)