I would like find a matrix from a row and column vectors
2 views (last 30 days)
Show older comments
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 (501x201)size.But i found (501x501). 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
0 Comments
Accepted Answer
Honglei Chen
on 13 Aug 2012
Edited: Honglei Chen
on 13 Aug 2012
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).';
0 Comments
More Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!