Connect 3D Scatter points through a line (2024)

33 views (last 30 days)

Show older comments

JB B on 26 Nov 2018

  • Link

    Direct link to this question

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line

  • Link

    Direct link to this question

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line

Edited: Image Analyst on 31 Mar 2021

So, I have a 3D scatter plot that I would like to connect every point to one another by using line. If someone can guide me to that, I would greatly be appreciated.3dsca

6 Comments

Show 4 older commentsHide 4 older comments

Walter Roberson on 26 Nov 2018

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642656

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642656

To check: if you had (say) 7 points, then you would want each point to have a line to each of the other 6 points? A "complete graph" in graph theory terms?

Or are you wanting to connect to points that are "adjacent" ?

JB B on 26 Nov 2018

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642662

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642662

I want them to connect to the points that are adjacent to one another in 3d.

Walter Roberson on 26 Nov 2018

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642678

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642678

Okay, so now: given lists of x, y, z, in which the entries are not ordered relative to each other but x(K) corresponds to y(K) and z(K), then: how do you determine whether [x(J), y(J), z(J)] is adjacent to [x(K), y(K), z(K)] ? Is there a cut-off distance? k nearest neighbours ?

JB B on 26 Nov 2018

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642680

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642680

There is no cut-off distance. I would like it to connect every point to the points around it, if that makes more sense to you.

Walter Roberson on 26 Nov 2018

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642685

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_642685

It would make sense to connect every point to every other point. Otherwise there has to be a rule to determine whether a point is "around" another point.

Let us take an example of reasonable size:

rng(1);a = randi(10,10, 3);

scatter3(a(:,1), a(:,2), a(:,3));

Now, which points are to be connected to which?

JB B on 27 Nov 2018

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_643125

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_643125

I think you are correct. How would I connect every point to every other point?

Thank you,

Sign in to comment.

Sign in to answer this question.

Answers (1)

Image Analyst on 27 Nov 2018

  • Link

    Direct link to this answer

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#answer_349230

  • Link

    Direct link to this answer

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#answer_349230

This should connect every point to every other point (untested)

hold on;

for k1 =1 : length(x)-1

for k2 = k : length(x)

plot3([x(k1), x(k2)], [y(k1), y(k2)], [z(k1), z(k2)], 'b-');

end

end

If you don't want all points connected to all other points, but only "adjacent" ones, then you have to define "adjacent" or "around". Is it only the nearest other point? Or 5 nearest?

4 Comments

Show 2 older commentsHide 2 older comments

Lukas on 31 Mar 2021

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1429819

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1429819

Hey, how do you only connect the nearest points?

x=[EEG.chanlocs.X];

y=[EEG.chanlocs.Y];

z=[EEG.chanlocs.Z];

(x,y,z are 64 channels with their respective location (1x64))

[xi, yi ] = meshgrid(x,y);

F = scatteredInterpolant(x',y',z','natural','none');

zi=F(xi,yi);

rotate3d on

hold on;

plot3(x, y, z,'r.')

Lukas on 31 Mar 2021

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1429824

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1429824

8 nearest

Lukas on 31 Mar 2021

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1429834

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1429834

cut-off distance would be okay, but would need to be defined. Points are relatively evenly spaced (head-shaped)

Image Analyst on 31 Mar 2021

Direct link to this comment

https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1430949

  • Link

    Direct link to this comment

    https://www.mathworks.ru/matlabcentral/answers/432100-connect-3d-scatter-points-through-a-line#comment_1430949

Edited: Image Analyst on 31 Mar 2021

@Lukas Gaßmann Start your own question with your EEG data attached in a .mat file and we'll show you how you can use pdist2() to find close points.

In the meantime, try the code below and if it helps you click on the Vote button near my top answer.

numPoints = 200;

x = 10 * rand(numPoints, 1);

y = 10 * rand(numPoints, 1);

z = 10 * rand(numPoints, 1);

subplot(2, 1, 1);

plot3(x, y, z, 'b.');

grid on;

title('Histogram of Distances');

% Find distance of every point to every other point.

xyz = [x, y, z];

distances = pdist2(xyz, xyz)

subplot(2, 1, 2);

histogram(distances);

grid on;

title('Histogram of Distances');

% Find distances closer than 3 units.

threshold = 1;

[index1, index2] = find(distances <= threshold)

indexes = unique([index1, index2], 'rows')

xline(threshold, 'Color', 'r', 'LineWidth', 2);

% For every pair of close points, draw a line.

subplot(2, 1, 1);

hold on;

for k = 1 : size(indexes, 1)

xPair = [x(indexes(k, 1)), x(indexes(k, 2))];

yPair = [y(indexes(k, 1)), y(indexes(k, 2))];

zPair = [z(indexes(k, 1)), z(indexes(k, 2))];

plot3(xPair, yPair, zPair, 'r-', 'LineWidth', 2);

end

fprintf('Done running %s.m\n', mfilename);

Connect 3D Scatter points through a line (13)

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Image Processing and Computer VisionComputer Vision ToolboxRecognition, Object Detection, and Semantic SegmentationImage Category Classification

Find more on Image Category Classification in Help Center and File Exchange

Tags

  • 3dscatter
  • line
  • linear

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Connect 3D Scatter points through a line (14)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

Europe

Asia Pacific

Contact your local office

Connect 3D Scatter points through a line (2024)

References

Top Articles
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 5507

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.