Borrar filtros
Borrar filtros

Need help in plotting with datenum on x-axis

2 visualizaciones (últimos 30 días)
Hamza
Hamza el 27 de Sept. de 2012
Dear All
I am having problem in plotting i have a series of time data using:
out = datestr(ymdhms,'yyyy-mm-dd HH:MM:SS');
ymdhms was extracted from a text file.
I want to plot it against another: longi =
256.242843281354
296.110093347349
296.882496353185
296.94437904219
138.658299669575
339.725337924464
339.894431814869
338.304313807115
222.2399243596
222.3367026132
222.460979592124
222.463301950309
>> whos longi
Name Size Bytes Class Attributes
longi 975x1 7800 double
whos out
Name Size Bytes Class Attributes
out 975x19 37050 char
I get the error when plotting:
>> plot(out,longi)
Error using plot
Invalid first data argument
How can I plot with time of my interest? Below is my code for further understanding:
=====================================================================
24652 1996-063A ARABSAT-2B
Launched: 1996-11-13 (318) Start Date: 1996-06-12 (164)
Decayed: Stop Date: 2003-12-20 (354)
=====================================================================
1 24652U 96063A 96318.74847837 -.00000020 00000-0 00000+0 0 14
2 24652 3.9929 210.6007 7281127 177.7757 190.4436 2.27277888 06
1 24652U 96063A 96319.62211352 -.00000020 00000-0 00000+0 0 31
2 24652 3.9929 210.3183 7284735 178.4392 185.2995 2.27373269 12
1 24652U 96063A 96319.62351606 .00008082 00000-0 30835-2 0 24
2 24652 3.9764 210.1654 7280836 178.5436 186.6267 2.27380102 20
1 24652U 96063A 96319.62356237 .00009638 00000-0 38025-2 0 37
2 24652 3.9632 210.3512 7280110 178.4006 186.6625 2.27374993 25
1 24652U 96063A 96320.05952563 -.00002597 00000-0 -98092-3 0 63
2 24652 3.9623 210.1661 7275699 178.7092 185.6294 2.27896863 39
<end of file>
fid=fopen('2B.txt');
A=textscan(fid,'%s','HeaderLines',5);
Data=reshape(A{1}(1:end-3,:),9,[])';
fclose(fid);
l1=Data(1:2:end,:);
l2=Data(2:2:end,:);
epoch=l1(:,4); %complete epoch data
a = str2double(epoch);
y = fix(a/1000);
ymdhms = datevec(datenum(y,0,a - y*1000)); % corrected
[yearnow,~] = datevec(now);
ymdhms(:,1) = (ymdhms(:,1) <= rem(yearnow,2000))*100 + 1900 + ymdhms(:,1);
out = datestr(ymdhms,'yyyy-mm-dd HH:MM:SS');
i= l2(:,3); % inclination
OM=l2(:,4); % RAAN
ecc=l2(:,5); %Eccentricity
w=l2(:,6); %Argument of perigee
M=l2(:,7); %mean anomaly
% Finding Longitude
YYY=367*(year);
MMM=fix((7/4)*((year)+fix((month+9)/12)));
MMM2=fix(275*(month/9));
DDD=day-730531.5;
SMH=(((((sec)/60)+min)/60)+hour)/24;
TT=YYY-MMM+MMM2+DDD+SMH;
GST0=280.46061837 + (360.98564736629 *TT);
mmod=mod(GST0,360);
Ln=cellfun(@str2double,OM)+cellfun(@str2double,M)+cellfun(@str2double,w)- mmod;
longi=mod(Ln,360);

Respuestas (1)

Thomas
Thomas el 27 de Sept. de 2012
Editada: Thomas el 27 de Sept. de 2012
You cannot plot a datestr (i.e. out which is a str) against an integer (long: please try to use a variable name other than long )
plot(ymdhms,long)
datetick('x',yyyy-mm-dd HH:MM:SS')
if it is in datenum format
otherwise
out=datenum(ymdhms,'yyyy-mm-dd HH:MM:SS');
plot(out,long)
datetick('x',yyyy-mm-dd HH:MM:SS')
  1 comentario
Hamza
Hamza el 27 de Sept. de 2012
Dear Tom
Thanks again!
actually ymdhms is a 6 column integer. so when i plot it the result is 6 lines. I have updated my question and given the code. I just want to plot 'out' against 'longi'

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by