MATLAB: I would like find a matrix from a row and column vectors

for loopMATLABmatrix manipulation

Hello, I have a column vector xxb of 201 elements and a row vector rr of 501 elements and I would calculate c =xxb^2+rr^2-R^2 with R=0.05. I have to obtain a matrix of (501×201)size.But i found (501×501). Here is below my code. Anyone has a idea. Thank you in advance, Adam
xb=-5:0.05:5;
xxb=xb';% column vector
r=0:0.01:5;
rr=r;% Row vector
R= 0.05;
for l=1:length(xxb);
for m=1:length(rr);
a(l)=2.*xxb(l);
c(l,m)=xxb(l).^2+rr(m).^2+R^2;
end
end

Best Answer

If you want 501x201, then you may want to make rr a column and xxb a row
rr = rr(:);
xxb = xxb(:).';
c = bsxfun(@plus,rr.^2,xxb.^2)+R^2;
or with your current configuration
c = (bxsfun(@plus,xxb.^2,rr.^2)+R^2).';