how to store all your values from a loop into a vector
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!