For Loop calculating too slowly
이전 댓글 표시
The code I am running now takes way too long to go through all the iterations to calculate the direction cosine matrix (DCM) for each second, minute, hour. I am using the function 'dcmeci2ecef' in the aerospace toolbox to calculate a DCM that I need to continue. I know there should be better ways to write this that does not take a long time to go through each iteration and display each individual DCM through the course of 24 hours. Any ideas?
for i = 0:24 % hours
for j = 0:60 % minutes in a hour
for k = 0:60 % seconds in a min
dcm_FI = dcmeci2ecef('IAU-2000/2006',[2019 9 30 i j k]);
end
end
end
답변 (1개)
darova
2019년 10월 2일
Maybe try
[S,M,H] = ndgrid(0:60, 0:60, 0:24);
data1 = repmat([2019 9 30],[length(S(:)) 1]);
data2 = [H(:) M(:) S(:)];
data = [data1 data2];
dcm_FI = dcmeci2ecef('IAU-2000/2006', data)
댓글 수: 1
Note that length(S(:)) is simply numel(S).
A simpler way to create that data matrix would be:
data = datevec(datetime(2019, 9, 30) + seconds(0:60*60*24-1)')
카테고리
도움말 센터 및 File Exchange에서 Axes Transformations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!