Find higher value with respect to time from a table?

 Accepted Answer

[Edit: add code to display satellite at maxAz and satellite at maxEl.)
I understand now that you wish to find the max azimuth and max elevation within a specified time window. You can do it as follows:
T=readtable('data139a.txt'); % read tabular data from file
dt=datetime(T.(1),'InputFormat','yyyy/MM/dd')+T.(2); % make a datetime vector
% Combine datetime vector with the other columns to make a timetable.
TT=timetable(dt,T.(3),T.(4),T.(5),T.(6),T.(7)); % make a timetable
% Extract all rows within specified time range:
dt1=datetime('19-May-2022 12:00:00'); % dt1=start datetime
dt1s=string(dt1,'HH:mm:ss'); % string for dt1
dt2=datetime('19-May-2022 12:00:30'); % dt2=end datetime
dt2s=string(dt2,'HH:mm:ss'); % string for dt2
TTsmall=TT(dt>=dt1 & dt<dt2,:); % timetable with dt1<=datetime<dt2
% Find the max Az and max EL, in the specified time range
[maxAZ,maxAZidx]=max(TTsmall.Var2);
[maxEL,maxELidx]=max(TTsmall.Var3);
% Use maxAZidx or maxELidx to find other properties associated with the
% maximum, such as satellite name, SNR at max El, etc.
% Display results
fprintf('Total table rows: %d.\n',height(TT)); ...
fprintf('%d table rows have %s<=datetime<%s.\n',height(TTsmall),dt1s,dt2s);...
fprintf('%s<=time<%s:\n',dt1s,dt2s); ...
fprintf('Max AZ=%.1f, satellite %s\n',maxAZ,string(TTsmall.Var1(maxAZidx))); ...
fprintf('Max EL=%.1f, satellite %s\n',maxEL,string(TTsmall.Var1(maxELidx)))
Total table rows: 8346.
3 table rows have 12:00:00<=datetime<12:00:30.
12:00:00<=time<12:00:30:
Max AZ=249.1, satellite G10
Max EL=20.3, satellite G10
The code above finds the max azimuth and max elevation within a specfied time window, and displays the results. There are other ways to do it, which would have fewer lines of code.
Good luck.

10 Comments

I have run this code and found an error. I have attached the schreenshot of the error.
The code failed because the file data139a.txt was not in a directory that Matlab looks in. Please download the file data139a.txt from our Matlab Answers discussion, and put in in the same directory as your script. Or change the change line 1 of the script to
T=readtable('139.txt');
to read your original file, and make sure 139.txt is in the same directory as your script, or add its directory to the Matlab path.
Thank you for your support. How can i get continoues time series of the data?
For example:
Time Max Azimuth Maz Elevation
00:00:00
00:00:30
00:01:00
..............
23:59:30
Make a for loop. On each loop pass, change dt1 and dt2, and find the max Az and Max El using the ideas in the code above. Store the results from each loop pass in an array.
I have tried but it hasn't work. Can you help me?
Please share what you have tried. Please explain how it did not work. I get better at coding by trying, failing, and trying again.
Thank you for your suggestion. I am also tried to learn matlab. I will remainber your advise.
Find my changes in the code
T=readtable('139.txt'); % read tabular data from file
dt=datetime(T.(1),'InputFormat','yyyy/MM/dd')+T.(2); % make a datetime vector
% Combine datetime vector with the other columns to make a timetable.
TT=timetable(dt,T.(3),T.(4),T.(5),T.(6),T.(7)); % make a timetable
% Extract all rows within specified time range:
dt1=datetime('19-May-2022 00:00:00'); % dt1=start datetime
dt1s=string(dt1,'hh:mm:ss'); % string for dt1
dt2=datetime('19-May-2022 11:59:30'); % dt2=end datetime
dt2s=string(dt2,'hh:mm:ss'); % string for dt2
TTsmall=TT(dt>=dt1 & dt<dt2,:); % timetable with dt1<=datetime<dt2
% Find the max Az and max EL, in the specified time range
for dt=1:104001
plot(dt1.(3),dt2.(4))
end
[~,maxAZidx]=max(TTsmall.Var2);
[~,maxELidx]=max(TTsmall.Var3);
maxAZ=TTsmall.Var2(maxAZidx);
maxEL=TTsmall.Var3(maxELidx);
% Display results
fprintf('Total table rows: %d.\n',height(TT)); ...
fprintf('Table rows with %s<=datetime<%s: %d.\n',dt1s,dt2s,height(TTsmall));...
fprintf('For %s<=time<%s, max AZ=%.1f, max EL=%.1f.\n',dt1s,dt2s,maxAZ,maxEL)
Make a vector of starting times for each interval, as follows:
dt1=datetime('19-May-2022')+seconds(0:30:86370);
Confirm that the start times are what you want:
disp([dt1(1),dt1(2),dt1(end-1),dt1(end)])
19-May-2022 00:00:00 19-May-2022 00:00:30 19-May-2022 23:59:00 19-May-2022 23:59:30
Make a vector of ending times for each interval as follows:
dt2=dt1+seconds(30);
Confirm that the end times are what you want:
disp([dt2(1),dt2(2),dt2(end-1),dt2(end)])
19-May-2022 00:00:30 19-May-2022 00:01:00 19-May-2022 23:59:30 20-May-2022 00:00:00
Inside the for loop, use dt1(i) and dt2(i) to define the time interval to search.
The earlier script created a small timetable with the rows in the specified time interval. Then I found the max Az and max El, in the small timetable.
%earlier script
TTsmall=TT(dt>=dt1 & dt<dt2,:); % timetable with dt1<=datetime<dt2
[maxAZ,maxAZidx]=max(TTsmall.Var2);
[maxEL,maxELidx]=max(TTsmall.Var3);
The new script does not create a small timetable. It finds the maximum within the rows of the big timetable whose times are within the interval. Also, the new script does not need the indices, so I do not find them.
% new script
maxAz(i)=max(TT.Var2(dt>=dt1(i) & dt<dt2(i)));
maxEL(i)=max(TT.Var3(dt>=dt1(i) & dt<dt2(i)));
The full script is attached. It creates the following output on the colsole:
>> satelliteAzEl
Total table rows: 104002, intervals=2880.
>>
It also makes the plot below:
The satellite with max elevation at a given time is usually different than the the satellite with maximum azimuth at the same time.
Good luck.
Thank you for your continous support and help.

Sign in to comment.

More Answers (2)

Convert data into an easier to read format
!unzip 139.zip
Archive: 139.zip inflating: 139.txt
!head 139.txt
% TIME (GPST) SAT AZ(deg) EL(deg) SNR(dBHz) L1 MP(m) 2022/05/19 00:34:30.0 G01 146.7 15.6 28.50 0.0000 2022/05/19 00:39:00.0 G01 144.9 16.4 31.31 0.0000 2022/05/19 00:40:00.0 G01 144.4 16.6 31.81 0.0000 2022/05/19 00:43:30.0 G01 143.0 17.2 32.44 0.0000 2022/05/19 00:44:00.0 G01 142.8 17.3 34.13 0.3673 2022/05/19 00:44:30.0 G01 142.6 17.4 31.69 0.4631 2022/05/19 00:45:00.0 G01 142.4 17.5 32.88 1.2921 2022/05/19 00:45:30.0 G01 142.2 17.6 32.06 -0.1025 2022/05/19 00:46:00.0 G01 142.0 17.7 30.66 1.2019
!sed -i 's/ */,/g' 139.txt
!sed -i 's/EL(deg) SNR(dBHz)/EL(deg),SNR(dBHz)/g' 139.txt
!head 139.txt
% TIME (GPST),SAT,AZ(deg),EL(deg),SNR(dBHz),L1 MP(m) 2022/05/19 00:34:30.0,G01,146.7,15.6,28.50,0.0000 2022/05/19 00:39:00.0,G01,144.9,16.4,31.31,0.0000 2022/05/19 00:40:00.0,G01,144.4,16.6,31.81,0.0000 2022/05/19 00:43:30.0,G01,143.0,17.2,32.44,0.0000 2022/05/19 00:44:00.0,G01,142.8,17.3,34.13,0.3673 2022/05/19 00:44:30.0,G01,142.6,17.4,31.69,0.4631 2022/05/19 00:45:00.0,G01,142.4,17.5,32.88,1.2921 2022/05/19 00:45:30.0,G01,142.2,17.6,32.06,-0.1025 2022/05/19 00:46:00.0,G01,142.0,17.7,30.66,1.2019
Read data into a timetable
opts = detectImportOptions("139.txt",ReadVariableNames=true,NumHeaderLines=0,VariableNamingRule="preserve",TextType="string");
opts = setvaropts(opts,"% TIME (GPST)",Type="datetime",InputFormat="uuuu/MM/dd HH:mm:ss.S");
tt = readtimetable("139.txt",opts)
tt = 104002×5 timetable
% TIME (GPST) SAT AZ(deg) EL(deg) SNR(dBHz) L1 MP(m) _____________________ _____ _______ _______ _________ ________ 2022/05/19 00:34:30.0 "G01" 146.7 15.6 28.5 0 2022/05/19 00:39:00.0 "G01" 144.9 16.4 31.31 0 2022/05/19 00:40:00.0 "G01" 144.4 16.6 31.81 0 2022/05/19 00:43:30.0 "G01" 143 17.2 32.44 0 2022/05/19 00:44:00.0 "G01" 142.8 17.3 34.13 0.3673 2022/05/19 00:44:30.0 "G01" 142.6 17.4 31.69 0.4631 2022/05/19 00:45:00.0 "G01" 142.4 17.5 32.88 1.2921 2022/05/19 00:45:30.0 "G01" 142.2 17.6 32.06 -0.1025 2022/05/19 00:46:00.0 "G01" 142 17.7 30.66 1.2019 2022/05/19 00:46:30.0 "G01" 141.8 17.8 32.03 -0.2771 2022/05/19 00:47:00.0 "G01" 141.6 17.9 32.06 -0.8351 2022/05/19 00:47:30.0 "G01" 141.4 18 31.38 -0.3719 2022/05/19 00:48:00.0 "G01" 141.2 18.1 33.31 -0.1552 2022/05/19 00:48:30.0 "G01" 141 18.2 33.38 0.7502 2022/05/19 00:49:00.0 "G01" 140.8 18.3 35.44 0.311 2022/05/19 00:49:30.0 "G01" 140.6 18.4 33.53 0.0172
Find the maximum elevation angle for each row time using groupsummary
groupsummary(tt,"% TIME (GPST)","max","EL(deg)")
ans = 2880×3 table
% TIME (GPST) GroupCount max_EL(deg) _____________________ __________ ___________ 2022/05/19 00:00:00.0 34 74.5 2022/05/19 00:00:30.0 35 74.7 2022/05/19 00:01:00.0 34 74.9 2022/05/19 00:01:30.0 34 75 2022/05/19 00:02:00.0 35 75.2 2022/05/19 00:02:30.0 35 75.3 2022/05/19 00:03:00.0 34 75.5 2022/05/19 00:03:30.0 35 75.7 2022/05/19 00:04:00.0 35 75.8 2022/05/19 00:04:30.0 35 76 2022/05/19 00:05:00.0 34 76.1 2022/05/19 00:05:30.0 35 76.3 2022/05/19 00:06:00.0 33 76.4 2022/05/19 00:06:30.0 34 76.6 2022/05/19 00:07:00.0 34 76.7 2022/05/19 00:07:30.0 34 76.9
Please explain exactly what you want to do in more detail. Provide an example of code you have tried that did not work.
Your file has 104,002 rows of data, which are observations of about 113 satellites.* The data is sorted by satellite and then by time. I have attached a shorter file with data from 10 satellites, to demonstrate code. Column 1=date, column 2=time of day. The observation times vary for different satelites. Some times are repeated many times through the table. All observations are on the same date.
Combine the date and time columns, to make a datetime array.
T=readtable('data139a.txt');
dt1=datetime(T.(1),'InputFormat','yyyy/MM/dd')+T.(2); % make a datetime vector
Combine the datetime array with the other columns to make a timetable.
TT=timetable(dt1,T.(3),T.(4),T.(5),T.(6),T.(7)); % make a timetable
Extract all rows that have a time greater than a specified time:
dtref=datetime('19-May-2022 11:59:59'); % dtref=reference datetime
TTpm=TT(dt1>dtref,:); % timetable with all times greater than dtref
To make a timetable containing the data for just one satellite (satellite G01, in this example), do this:
TTg01=TT(strcmp(TT.(1),'G01'),:); % timetable for satellite G01
*Satellites in file 139.txt: G01-G32, R01-R15, R17-R18, R20-R24, E01-E05, E07-E15, E18-E21, E24-E27, E30-E31, E33-E34, E36, J02-J04, J07, C19-C46.

4 Comments

Dear Rose,
Thank you for your support. I need maximum value with respect to time.
In the data set, every 30 second interval data are avalibale. how i can find max azimumth, max elevation with respect to time from all the satellites.
Do you want to find the max azimiuth and max elevation for each satellite?
Why do you want to find max azimuth? I am asking that quesiton because it seems to me that max azimuth is an unusual quantity to seek to know. The max azimuth probably occurs as the satellite is crossing a threshold of visibility or signal strength.
Some of the satellites in the record make multiple passes, and some do not. If you wan thte max for each pass you will have to add some code to identify separate passes.
Dear Rose, I don't want get each satellite maximum elevation angle. I just want maximum elevation angle of a particular time.
For example, 00:00:00 time maximum elevation angle among all the satellite data present.

Sign in to comment.

Categories

Products

Community Treasure Hunt

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

Start Hunting!