Help with using arrays to create variables

조회 수: 1 (최근 30일)
Scott Hunter
Scott Hunter 2018년 10월 25일
댓글: Stephan 2018년 10월 25일
I'm trying to use arrays to create variables related to 32 different satellites (which I currently have fully written out it's awful making changes) orbiting a planet and am getting stuck quite early on. As a small example I'm trying to get working, I've got two angles for each satellite (being done in blocks of 8), th0(i) and th(i). The angle th0 works fine, however th relies upon th0 and a parameter, also an angle, called M, which relies on time. As I have 148 timesteps, M is a 148x1 array. When I input my code below, I get an error about the element numbers not matching up. I tried using the transverse of th and th0 but no joy. Can anyone suggest my next move?
%%Relevant parameters
timestep = 600;
G = 6.67408*10^-11; %[m^3kg^-1s^-2]
% Mars data
Mars.m = 6.39*10^23; %[kg]
Mars.mu = Mars.m*G; %[m^3s^-2]
Mars.r = 3389.5*10^3; %[m]
Mars.v = 241.17; %[ms^-1]
Mars.T = (2*pi*Mars.r)/Mars.v; %[s]
Mars.o = Mars.v/Mars.r; %[rads^-1]
Mars.th = Mars.o*timestep; %[rad] for every second
t = (0:timestep:Mars.T)'; %Mars.T, Length of martian day in seconds
H1 = 9610.5*10^3; %[m]
a1 = Mars.r + H1; %[m]
T1 = 2*pi*sqrt(a1^3/Mars.mu); %[s]
n1 = (2*pi)/T1; %[kms^-1]
M1 = n1*t; %[rad]
%%Test Section
th0 = zeros(1,length(t));
th = zeros(1,length(t));
for i = 1:8
th0(i) = deg2rad(45*(i-1));
th(i) = th0(i) + 2*atan(tan(M1/2));
end
  댓글 수: 4
Scott Hunter
Scott Hunter 2018년 10월 25일
Update;
If I change the test section to
th0 = zeros(1,length(t));
th = zeros(1,length(t));
for i = 1:8
th0(1,i) = deg2rad(45*(i-1));
th(1,i) = th0(1,i) + 2*atan(tan(M1/2));
end
I end up with "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 148-by-1."
Can't figure out what the 1 by 1 is?
Stephan
Stephan 2018년 10월 25일
Die you try the code from my answer?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephan
Stephan 2018년 10월 25일
Hi,
try:
%%Relevant parameters
timestep = 600;
G = 6.67408*10^-11;
% Mars data
Mars.m = 6.39*10^23; %[kg]
Mars.mu = Mars.m*G; %[m^3s^-2]
Mars.r = 3389.5*10^3; %[m]
Mars.v = 241.17; %[ms^-1]
Mars.T = (2*pi*Mars.r)/Mars.v; %[s]
Mars.o = Mars.v/Mars.r; %[rads^-1]
Mars.th = Mars.o*timestep; %[rad] for every second
t = (0:timestep:Mars.T)'; %Mars.T, Length of martian day in seconds
H1 = 9610.5*10^3; %[m]
a1 = Mars.r + H1; %[m]
T1 = 2*pi*sqrt(a1^3/Mars.mu); %[s]
n1 = (2*pi)/T1; %[kms^-1]
M1 = n1*t; %[rad]
%%Test Section
th0 = zeros(1,length(t));
th = zeros(1,length(t));
for i = 1:148
th0(i) = deg2rad(45*(i-1));
end
th = th0'+ 2*atan(tan(M1/2));
Best regards
Stephan
  댓글 수: 4
Scott Hunter
Scott Hunter 2018년 10월 25일
편집: Scott Hunter 2018년 10월 25일
Sorry yes I thought I had to do that to get it to work, here's my most recent attempt;
th0 = zeros(1,32);
th = zeros(1,32);
for i = 1:8
th0(i) = deg2rad(45*(i-1));
end
th = th0 + 2*atan(tan(M1/2));
This gives me a 148x32 which is progress! Not sure where to go next but I'll keep bashing on! Thanks for your help!
Stephan
Stephan 2018년 10월 25일
If my answer was useful for you please accept it. I wish you success.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by