How to store a vector under a for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Maria Gonzalez
am 26 Nov. 2015
Kommentiert: Maria Gonzalez
am 26 Nov. 2015
Hi, so I want to store theta as a vector under my for loop. But only the last number of theta saves, does anyone know how to get that as a vector?
clear all;
v = 5.8;
u = 1/v;
Psph = [509.35 507.06 504.77 398.20 394.19 389.61 268.71 266.99 265.85];
E = [];
r1= 6731;
r2= 6731;
pi = 3.1416;
theta=[];
for delta = [29 30 31 59 60 61 89 90 91]
theta = r1*sin(delta)*u;
end
E = Psph/((r1.^2)*(r2.^2)*4*pi*(u.^2)*sin(delta)*(cos(theta)).^2);
A = sqrt(E);
0 Kommentare
Akzeptierte Antwort
James Tursa
am 26 Nov. 2015
Bearbeitet: James Tursa
am 26 Nov. 2015
theta(delta) = r1*sin(delta)*u; % <-- Added the (delta) indexing
You will also need to change some of your matrix operators to element-wise operators. E.g.,
E = Psph./((r1.^2)*(r2.^2)*4*pi*(u.^2)*sin(delta).*(cos(theta)).^2);
But note that this entire loop:
for delta = [29 30 31 59 60 61 89 90 91]
theta(delta) = r1*sin(delta)*u;
end
can be replaced with these lines:
delta = [29 30 31 59 60 61 89 90 91]
theta = r1*sin(delta)*u;
Weitere Antworten (1)
Andrei Bobrov
am 26 Nov. 2015
v = 5.8;
u = 1/v;
Psph = [509.35 507.06 504.77 398.20 394.19 389.61 268.71 266.99 265.85];
r1= 6731;
r2= 6731;
pi = 3.1416;
delta = [29 30 31 59 60 61 89 90 91];
theta = r1*sin(delta)*u;
E = Psph./((r1.^2)*(r2.^2)*4*pi*(u.^2)*sin(delta).*(cos(theta)).^2);
A = sqrt(E);
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!