Help plotting two events that happened on the same day

1 vue (au cours des 30 derniers jours)
Arthur Romeu
Arthur Romeu le 28 Oct 2019
Commenté : Arthur Romeu le 1 Nov 2019
Hello everyone,
I am currently with this code right here:
plot_avistagens = table(data_avistagens,lat_avistagens,lon_avistagens);
plot_tracking = table(data_tracking_tratado,lat_tracking_tratado,lon_tracking_tratado);
here is how plot_avistagens is organised (first column is datetime)
'27-Sep-2019' -24,1304300000000 -41,5916700000000
'27-Sep-2019' -24,1280000000000 -41,5905200000000
'29-Sep-2019' -25,2749500000000 -41,1169800000000
'30-Sep-2019' -25,3730300000000 -41,3620800000000
'30-Sep-2019' -25,3766300000000 -41,4046500000000
'30-Sep-2019' -25,3780300000000 -41,4305200000000
'30-Sep-2019' -25,3780300000000 -41,4305200000000
'30-Sep-2019' -25,2720800000000 -41,6465300000000
'30-Sep-2019' -25,1177000000000 -41,8814000000000
'01-Oct-2019' -24,4056700000000 -41,8560000000000
'01-Oct-2019' -24,4056700000000 -41,8560000000000
'09-Oct-2019' -24,6301200000000 -40,6946300000000
and here is plot_tracking (first column also datetime)
'30-Sep-2019' -24,2857830000000 -41,7407100000000
'30-Sep-2019' -24,2598050000000 -41,7166830000000
'30-Sep-2019' -24,2284610000000 -41,6914590000000
'30-Sep-2019' -24,1944140000000 -41,6667960000000
'30-Sep-2019' -24,1683580000000 -41,6296230000000
'30-Sep-2019' -24,1460220000000 -41,5832420000000
'01-Oct-2019' -24,1260030000000 -41,5351400000000
'01-Oct-2019' -24,1162640000000 -41,4840100000000
'01-Oct-2019' -24,1061480000000 -41,4380680000000
'01-Oct-2019' -24,0954680000000 -41,3900660000000
'01-Oct-2019' -24,0850860000000 -41,3420080000000
Now my next step is plotting different charts for each day. The difficulty I'm facing is: I need a chart that shows all the events that happened on each day. However, my code just plots "DayGroups day 1" with "DayGroups_t day 1" and doesnt check if "DayGroups day 1" is the same day as "DayGroups_t day 1"
D = findgroups(datetime(plot_avistagens{:,1}));
DayGroups = accumarray(D, (1:size(D,1))', [], @(x){plot_avistagens(x,:)});
Dt = findgroups(datetime(plot_tracking{:,1}));
DayGroups_t = accumarray(Dt, (1:size(Dt,1))', [], @(x){plot_tracking(x,:)});
for k = 1:size(DayGroups_t,1)
figure(k)
plot(DayGroups{k}{:,2}, DayGroups{k}{:,3:end}, 'bp', DayGroups_t {k}{:,2}, DayGroups_t{k}{:,3:end}, 'r:')
grid
end
That ends up plotting things from Sep-27 with things from Sep-30 and so on. Any ideas on how to fix this?
Thanks!
  3 commentaires
Arthur Romeu
Arthur Romeu le 29 Oct 2019
I didn't know how to proceed so I created another one. Sorry
Star Strider
Star Strider le 29 Oct 2019
No worries!
I am just providing context.

Connectez-vous pour commenter.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 28 Oct 2019
I'm not sure what it is you want to display on your final figure.
First, for others, here's the data in a way you can quickly create the variables used.
data_avistagens = datetime({'27-Sep-2019'
'27-Sep-2019'
'29-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'01-Oct-2019'
'01-Oct-2019'
'09-Oct-2019'});
lat_avistagens = [-24.13043
-24.128
-25.27495
-25.37303
-25.37663
-25.37803
-25.37803
-25.27208
-25.1177
-24.40567
-24.40567
-24.63012];
lon_avistagens = [-41.59167
-41.59052
-41.11698
-41.36208
-41.40465
-41.43052
-41.43052
-41.64653
-41.8814
-41.856
-41.856
-40.69463];
data_tracking_tratado = datetime({'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'30-Sep-2019'
'01-Oct-2019'
'01-Oct-2019'
'01-Oct-2019'
'01-Oct-2019'
'01-Oct-2019'});
lat_tracking_tratado = [-24.285783
-24.259805
-24.228461
-24.194414
-24.168358
-24.146022
-24.126003
-24.116264
-24.106148
-24.095468
-24.085086];
lon_tracking_tratado = [-41.74071
-41.716683
-41.691459
-41.666796
-41.629623
-41.583242
-41.53514
-41.48401
-41.438068
-41.390066
-41.342008];
plot_avistagens = table(data_avistagens,lat_avistagens,lon_avistagens);
plot_tracking = table(data_tracking_tratado,lat_tracking_tratado,lon_tracking_tratado);
It looks like you are trying to create a plot for each day that just displays the events that occurred on that day?
Using the variables I created, I would do it like this.
Ds = categorical([data_avistagens;data_tracking_tratado]);
D = categories(Ds);
for d = 1:length(D)
idxD = data_avistagens==D(d);
idxDt = data_tracking_tratado==D(d);
figure
plot(plot_avistagens.lat_avistagens(idxD),plot_avistagens.lon_avistagens(idxD),'bp');
hold on
plot(plot_tracking.lat_tracking_tratado(idxDt),plot_tracking.lat_tracking_tratado(idxDt),'ro');
hold off
xlabel("Lat")
ylabel("Lon")
title(D(d))
end
You might want to looking into using gscatter to create a group scatter plot using the date as the grouping variable (I've converted it to a categorical so I could do this).
figure
gscatter(plot_avistagens.lat_avistagens,plot_avistagens.lon_avistagens,plot_avistagens.data_avistagens)
grid on
figure
gscatter(plot_tracking.lat_tracking_tratado,plot_tracking.lon_tracking_tratado,plot_tracking.data_tracking_tratado)
grid on
This is creating 2 separate figures.
To be honest, I couldn't understand what exactly it was you wanted to display. Perhaps this is enough to help you get started?
  3 commentaires
Cris LaPierre
Cris LaPierre le 31 Oct 2019
The simplest way I've found is the following:
figure
gscatter([plot_avistagens.lat_avistagens;plot_tracking.lat_tracking_tratado],[plot_avistagens.lon_avistagens; plot_tracking.lon_tracking_tratado],categorical([plot_avistagens.data_avistagens;plot_tracking.data_tracking_tratado]))
grid on
There is probably a better way to join the data, but here you can see what is happening.
All data will have the same symbol, but it should be fairly obvious where the boat is vs where the marine mammals are.
ArthruRomeu_plot.png
Arthur Romeu
Arthur Romeu le 1 Nov 2019
thanks!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Preprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by