フィルターのクリア

Iterating Structures:

1 回表示 (過去 30 日間)
David
David 2011 年 12 月 13 日
I am currently trying to write a matlab program that has ALOT of information to use. Currently I am using all arrays, because I cannot figure out how to iterate through structures. Now I am at a point that I can either make three arrays to hold XYZ coordinates, or I can make a structure where I can store all 3 coordinates in horizontal slots. So far I am running 2 for loops, where prn is the main loop running from 1 to 10, and an inner loop "index" which runs from 1 to 931. Basically I am computing satellite position XYZ coordinates each second, where 1 to 10 is the satellite, and 1 to 931 is the time frame that info was recorded. Here is a sample of my code:
xK(prn) = xP(prn)*cos(omegaP(prn)) - yP(prn)*sin(omegaP(prn))*cos(i(prn));
yK(prn) = xP(prn)*sin(omegaP(prn)) + yP(prn)*cos(omegaP(prn))*cos(i(prn));
zK(prn) = yP(prn)*sin(i(prn)); SV.xyz = [xK yK zK];
This last line poses a problem because it is re-written every second, so my data only exits for 931 but uses all satellites. I was wondering if there is any other way to do this? It may be too late, but I was also wondering if there was a way to iterate through structures? I would like to have a main structure PRN that has subfields .1 .2 .3 etc for each satellite and then each of those has satellite information during each second. But since you cannot name fields with a number, it is a problem. Sorry if I am unclear, just ask me to clarify something if it doesn't make sense.
thanks David

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 12 月 13 日
nsat = 10;
xPv = xP(:);
yPv = yP(:);
oPv = omegaP(:);
coPv = cos(oPv);
soPv = sin(oPv);
iv = i(:);
civ = cos(iv);
siv = sin(iv);
SV(nsat).xyz = []; %pre-initialize struct array
for S = 1 : nsat
xK = xPv * coPv - yPv * soPv * civ;
yK = xPv * soPv - yPv * coPv * civ;
zK = yPv * siv;
SV(S).xyz = [xK, yK, zK];
end
Outputs: array SV, with SV(1).xyz, SV(2).xyz and so on
Note: xyz will now be an array 931 by 3, with the columns being x y z. Your current code appears to arrange them all in a single row vector.

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by