how to store all your values from a loop into a vector

1 回表示 (過去 30 日間)
Ash
Ash 2019 年 5 月 1 日
コメント済み: Ash 2019 年 5 月 1 日
I am trying to store all the values of P i get from this loop, but it only returns the last value.
% h k radius
A=[-7.3763 7.6512 7.8
3.5199 1.0563 5.6
5.2646 -4.8721 10.0
2.1783 -0.5596 4.9
-5.4952 2.1826 3.5];
[n,m]=size(A);
a=1;
while a<n
for s=(a+1):n
fun=@(x) [(x(1).^2)+(x(2).^2)-2*(x(1)*A(s,1)+x(2)* A(s,2))+(A(s,1)^2)+(A(s,2)^2)-(A(s,3)^2)...
(x(1).^2)+(x(2).^2)-2*(x(1)*A(a,1)+x(2)* A(a,2))+(A(a,1)^2)+(A(a,2)^2)-(A(a,3)^2)];
% equation of a circle ((x-h)^2)+((y-k)^2)-r^2=0, (expanded out)
B=[A(a,1),A(a,2)-A(a,3)];%guess
P=fsolve(fun,B)
end
a=a+1;
end

採用された回答

KSSV
KSSV 2019 年 5 月 1 日
% h k radius
A=[-7.3763 7.6512 7.8
3.5199 1.0563 5.6
5.2646 -4.8721 10.0
2.1783 -0.5596 4.9
-5.4952 2.1826 3.5];
[n,m]=size(A);
a=1;
count = 0 ;
P = zeros([],2) ;
while a<n
for s=(a+1):n
fun=@(x) [(x(1).^2)+(x(2).^2)-2*(x(1)*A(s,1)+x(2)* A(s,2))+(A(s,1)^2)+(A(s,2)^2)-(A(s,3)^2)...
(x(1).^2)+(x(2).^2)-2*(x(1)*A(a,1)+x(2)* A(a,2))+(A(a,1)^2)+(A(a,2)^2)-(A(a,3)^2)];
% equation of a circle ((x-h)^2)+((y-k)^2)-r^2=0, (expanded out)
B=[A(a,1),A(a,2)-A(a,3)];%guess
count = count+1 ;
P(count,:)=fsolve(fun,B)
end
a=a+1;
end
  1 件のコメント
Ash
Ash 2019 年 5 月 1 日
Thanks! worked out great

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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