3D data plotting from data acquisition

6 views (last 30 days)
jim o
jim o on 25 Jul 2018
Answered: Jacob Mathew on 3 Dec 2024 at 8:08
Hello, I am new to matlab and I am trying to 3D plot data from a .dat file in matlab. The format for the data file is as follows:
xPosition yPosition zPosition xData yData zData
each of these are vectors which have a dimension of (59464 x 1).
The problem I am having is associating the xPosition with xData, yPosition with yData, and the zPosition with zData. Here is the code I am using.
plot3(xPos,yPos,zPos,xField,yField,zField)
grid on
which gives me this plot
When I try to plot the data using plot3(), matlab doesn't know how to associate the data within these vectors, so what ends up happening is that all of the data is plotted at once.
I eventually want to have each xPos corresponding with xData (for y and z also). If there is any way to reformat the data so that I can use this for the contour plot and streamline functions this data set, please let me know. Thanks.

Answers (1)

Jacob Mathew
Jacob Mathew on 3 Dec 2024 at 8:08
Hey jim,
You could try plotting the data using the quiver3 method. This method lets you plot vectors with a head and a tail, letting you better analyse them. A simple example with some sample data is as follows:
% Number of vectors
numVectors = 10;
% Generate random positions (xPosition, yPosition, zPosition)
xPosition = rand(numVectors, 1) * 10;
yPosition = rand(numVectors, 1) * 10;
zPosition = rand(numVectors, 1) * 10;
% Generate random vector components (xData, yData, zData)
xData = randn(numVectors, 1);
yData = randn(numVectors, 1);
zData = randn(numVectors, 1);
% Plot using quiver3
figure;
quiver3(xPosition, yPosition, zPosition, xData, yData, zData, 'AutoScale', 'on');
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3D Vector Field');
grid on;
axis equal;
You can refer to the documentation for quiver3 as follows:

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!