MATLAB: Adding matrices with different dimensions

bsxfundifferent dimensions

I got an equation similar to this : X-sin(thita). size(X) = 1×50 size(thita) = 1×180.
My output should be a matrix of 50×180. It could be done easily by using 2 for-loop but i am trying to find something more efficient. I tried bsxfun() but i could not manage it.
Thanks in advance

Best Answer

Convert X to a column vector. Then bsxfun will do what you want.
For example
X = rand(1, 50);
thita = rand(1, 180);
Xthitadiffs = bsxfun(@minus, X.', sin(thita)); % transpose on X makes column