フィルターのクリア

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

1 回表示 (過去 30 日間)
adam
adam 2012 年 8 月 13 日
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

採用された回答

Honglei Chen
Honglei Chen 2012 年 8 月 13 日
編集済み: Honglei Chen 2012 年 8 月 13 日
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).';

その他の回答 (1 件)

adam
adam 2012 年 8 月 14 日
Hello Honglei,
Thank you for your answer. I managed finally to obtain my matrix using for loop. The aim of this code is to find the area of the intersection of two cercles that must to be matrix in order to use it in another code.But I can't find the good result. Here below my code. May be have you an idea. thank you very much in advance.
if true
xb=-5:0.05:5;
xxb=xb';
dr=0.01;
r=0:dr:5;
rr=r;% colonne ligne
ABDN1=ABDN;% colonne ligne
w2=2.25;
R= 0.05;
for l=1:length(xxb);
for m=1:length(rr);
% paramètres a,c,xp,yp
a(l)=2.*xxb(l);
c(l,m)=xxb(l).^2+rr(m).^2-R^2;
if (a(l)>0) &(a(l)<0)
xp(l,m)=c(l,m)./a(l);
yp(l,m)=R^2-((((2.*c(l,m))-(a(l).^2))./(2.*a(l))).^2);
else
xp(l,m)=0;
yp(l,m)=0;
end
% angle theta
theta(l,m)=atan((sqrt(yp(l,m)))./xp(l,m));
if R<rr(m) inter(l,m)=0;
elseif xxb(l)==0 inter(l,m)=2*pi;
elseif xxb(l)<abs(R-r(m)) inter(l,m)=2.*pi; elseif xxb(l)>r(m)+R inter(l,m)=0;
else
inter(l,m)=(atan((sqrt(yp(l,m)))./xp(l,m)));
% part1(l,m)= (r(m).^2).*acos((xxb(l).^2 + r(m).^2 - R^2)/(2.*xxb(l).*r(m))); % part2(l,m) = (R^2).*acos((xxb(l).^2+ R ^2- r(m).^2)/(2.*xxb(l).*R)); % part3(l,m) = 0.5.*sqrt((-xxb(l)+r(m)+R)*(xxb(l)+r(m)-R)*(xxb(l)-r(m)+R)*(xxb(l)+r(m)+R)); % % inter(l,m) = part1(l,m) + part2 (l,m)- part3(l,m);
end
end
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by