how to store all your values from a loop into a vector
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
KSSV
on 1 May 2019
% 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
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!