How to plot variability (max/min) of large data set?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a very large data set with many trials of x coordinate, y coordinate, and time (ms). I am trying to graph the max and min distances between x/y points at each time. Any advice?
댓글 수: 0
답변 (1개)
Rahul
2025년 7월 18일
Hi Julia,
I understand you are working with a large dataset containing multiple trials of '(x, y)' coordinates over time, and you are trying to compute and plot the maximum and minimum distances between points at each time step.
One efficient way to do this in MATLAB is to loop through each unique time value, compute the pairwise distances between all '(x, y)' points at that time, and then extract the min and max distances.
Here is how you can implement the same using MATLAB script:
% Assuming your data is in a table or array format with columns: time, x, y
times = unique(data(:,1)); % Get unique time points
nTimes = length(times);
maxDist = zeros(nTimes,1);
minDist = zeros(nTimes,1);
for i = 1:nTimes
t = times(i);
idx = data(:,1) == t;
xy = data(idx, 2:3); % Get [x y] at current time
if size(xy,1) > 1
D = pdist(xy); % Compute pairwise distances
maxDist(i) = max(D);
minDist(i) = min(D);
else
maxDist(i) = 0;
minDist(i) = 0;
end
end
% Plot results
figure;
plot(times, maxDist, 'r-', 'DisplayName', 'Max Distance');
hold on;
plot(times, minDist, 'b-', 'DisplayName', 'Min Distance');
xlabel('Time (ms)');
ylabel('Distance');
legend('show');
title('Min and Max Distance Between Points Over Time');
grid on;
This approach uses 'pdist'function for performing pairwise operations, which is efficient for computing all pairwise Euclidean distances. You can adapt it further based on how your data is structured (matrix, table, etc.).
For more information regarding the usage of 'pdist' function, you can refer to the following documentation link:
Best!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!