Data points in an imaginary grid cell
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear all,
I have a list of data points in two dimensions that correspond to the coordinates (longitude and latitude) of my vessels. Then there is also a third variable, connected to each vessel position, that corresponds to time.
Now I want to define an imaginary grid and plot those vessels into a plot, but instead of plotting all points/vessels I just want identify the cells that have vessels and consider one equivalent vessel in those grid cells during a specific period of time (let’s say one hour).
I'm a bit lost on this. Thank you in advance for your help.
2 comentarios
Voss
el 29 de Nov. de 2022
Here's one way to read the data and plot the lat/lon for all times:
fid = fopen('Pasta1.csv');
data = fread(fid,'*char').';
fclose(fid);
data = strsplit(data,{';' sprintf('\r\n')});
if isempty(data{end})
data(end) = [];
end
data = reshape(data,3,[]).';
data(1,:) = [];
data(:,[1 2]) = num2cell(str2double(data(:,[1 2])));
% Note the warning below: ambiguous format, i.e., does "01/07" mean "Jan 7" or "Jul 1"?
% (There's no way for me to know the answer to that.)
data(:,3) = num2cell(datetime(data(:,3)));
plot([data{:,1}],[data{:,2}],'.')
Can you explain more about what grid you want to impose on these points, and for what purpose? In particular, it's not clear to me what you mean by, "consider one equivalent vessel".
Respuestas (1)
Tushar
el 5 de Sept. de 2023
Hi Ricardo,
I understand that you are trying to find out the number of vessels in a rectangular grid area.
%converting to an array
data_array = [cell2mat(data(:,1)),cell2mat(data(:,2))];
%define shape of the rectangular grid box that you want
length=5; width=10;
rect_number=grid_func(length,width,data_array(1,:));
num_points=points_func([0 6],length,width,data_array);
function rectangle_number = grid_func(length, width, x)
rectangle_number= [fix(x(1)/width) fix(x(2)/length)];
end
function number_of_points = points_func(rectangle_number,length, width, data_array)
len = [rectangle_number(1)*length, (rectangle_number(1) + 1)*length];
wid = [rectangle_number(2)*width, (rectangle_number(2) + 1)*width];
x_indices = find(data_array(:,1)>len(1) & data_array(:,1)<len(2));
y_indices = find(data_array(:,2)>wid(1) & data_array(:,2)<wid(2));
number_of_points = size(intersect(x_indices,y_indices));
number_of_points=number_of_points(1);
end
The rectangular grid that I have assumed-
- Rectangle number will have two coordinates: [X Y]
- X=0 and Y=0 for the first rectangle on the first quadrant
You can even calculate the rectangle number for any point. I hope these functions will be helpful for you.
0 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!