How to create matrices from a table and extract specific data from it to make plots?

46 visualizzazioni (ultimi 30 giorni)
I'm sorry if the title is confusing. But I'm stuck at a point and I will appreciate any tip or help!
I'm reading a series of AIS data from an excel file (.xlsx) and one of my targets is to plot the trajectories of each vessel. But I also need to preserve/store all data for further analysis.
I've attached a sample data file. (sample.xlsx) I have the following code. (My apologies for the sloppiness, any tips for improvements is appreciated)
% Load the AIS data file from the path specified
Data_file = readtable('sample.xlsx');
% Adjust the numbers according to the columns (mmsi, time, LAT, LON, SOG, COG, L and B))
AISdata = Data_file(:, [2, 3, 4, 6, 7, 8, 9, 10]);
% Sorting the data. First by MMSI and then by Time
AISdata_srt = sortrows(AISdata, [1 4]); % [MMSI TIME]
% Ship dimension table
dim = AISdata_srt(:, [1, 7, 8]);
dimensions = unique(dim(:,:), 'rows');
% Grouping the data series by MMSI
G = findgroups(AISdata(:,1));
M = accumarray(G, (1:size(AISdata,1)).', [], @(x){AISdata(x,:)});
What I think I need is a loop to take each cell "group" from M and convert it to an array. Then extract its Latitude-Longitude data as X-Y (cartesian) data and plot them. All I could think of is a pseudo loop like this. But I don't know how to implement it.
for 1:(Number of Groups in M)
> (Take one group)
> (convert it to a matrix)
> (Extract LON LAT data)
> (plot hold on)
How can I do this?
Again, my apologies for the sloppy code, I'm still learning.

Risposta accettata

Cris LaPierre
Cris LaPierre il 29 Dic 2020
As Adam told you in your previous post, you can just work with the data in the table. No need to extract it somewhere else. See the page Access Data in Tables.
% Load the AIS data file from the path specified
AISdata = readtable('Jamessample.xlsx');
% Grouping the data series by MMSI
G = findgroups(AISdata.mmsi);
hold on
for g = 1:max(G)
hold off

Più risposte (0)


Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by