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

1 Ansicht (letzte 30 Tage)
Ash
Ash am 1 Mai 2019
Kommentiert: Ash am 1 Mai 2019
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

Akzeptierte Antwort

KSSV
KSSV am 1 Mai 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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by