Clear Filters
Clear Filters

Plotting swept data in 3D plot without link between sweeps

1 view (last 30 days)
Hi everyone!
I want to plot my data in 3D without a link between sweeps. This is my current code.
M0dBmto15dBm_0offset_1msdelaya=table2array(M0dBmto15dBm_0offset_1msdelay);
X = reshape(M0dBmto15dBm_0offset_1msdelaya(1:end,1),3,[]);
Y = reshape(M0dBmto15dBm_0offset_1msdelaya(1:end,2),3,[]);
Z = reshape(M0dBmto15dBm_0offset_1msdelaya(1:end,4),3,[]);
surf(X,Y,Z,'FaceColor','interp')
Does anyone have any ideas on how to do this short of just creating loads of new arrays?

Answers (1)

Jaswanth
Jaswanth on 14 Jun 2024
Hi,
To plot 3D data without linking points across different sweeps, one effective approach is to use the ‘plot3’ function instead of the “surf” function . The ‘plot3’ function plots discrete points or lines in 3D space but does not automatically create a surface between these points.
To plot each sweep separately and avoid linking between them, you can loop through each sweep and plot them one at a time.
Please refer to the following example code to know how to plot 3D data using “plot3” function:
% Simulate some data for demonstration
% Let's assume we have 3 sweeps, each with 10 points.
numSweeps = 3;
pointsPerSweep = 10;
M0dBmto15dBm_0offset_1msdelay = array2table(rand(numSweeps * pointsPerSweep, 4)); % Random data
% Convert table to array
M0dBmto15dBm_0offset_1msdelaya = table2array(M0dBmto15dBm_0offset_1msdelay);
% Preparing data for plotting
X = reshape(M0dBmto15dBm_0offset_1msdelaya(:,1), pointsPerSweep, []);
Y = reshape(M0dBmto15dBm_0offset_1msdelaya(:,2), pointsPerSweep, []);
Z = reshape(M0dBmto15dBm_0offset_1msdelaya(:,4), pointsPerSweep, []);
% Plotting each sweep separately
figure; % Create a new figure
hold on; % Keep the plot window active to plot multiple sweeps
colors = lines(numSweeps); % Get some colors for the sweeps
for i = 1:numSweeps
plot3(X(:,i), Y(:,i), Z(:,i), 'o-', 'Color', colors(i,:)); % Plot each sweep with a unique color
end
hold off; % No more plots will be added
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Plot of Data without Linking Sweeps');
grid on; % Add a grid for better visualization
Please refer to the image below to see the 3D output of the above code:
Kindly refer to the following MathWorks documentation to know more about the “plot3” function: https://www.mathworks.com/help/matlab/ref/plot3.html?searchHighlight=plot3&s_tid=srchtitle_support_results_1_plot3
I hope the information provided above is helpful.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!