Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9023505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:46:38+00:00 2026-06-16T05:46:38+00:00

I have a matrix points X in 3 dimensions ( X is a Nx3

  • 0

I have a matrix points X in 3 dimensions (X is a Nx3 matrix) and those points belong to clusters. The cluster it belongs is given by the Nx1 vector Cluster (it has values like 1,2,3,…). So, I am plotting it on scatter3 like this:

scatter3(X(:,1),X(:,2),X(:,3),15,Cluster)

It works fine, but I would like to add a legend to it, showing the colored markers and the cluster it represents.

For example, if i have 3 clusters, I would like to have a legend like:

<blue o> - Cluster 1
<red o> - Cluster 2
<yellow o> - Cluster 3

Thank you very much for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:46:39+00:00Added an answer on June 16, 2026 at 5:46 am

    Instead of using scatter3, I suggest you use plot3, which will make labeling much simpler:

    %# find out how many clusters you have
    uClusters = unique(Cluster);
    nClusters = length(uClusters);
    
    %# create colormap
    %# distinguishable_colormap from the File Exchange 
    %# is great for distinguishing groups instead of hsv
    cmap = hsv(nClusters);
    
    %# plot, set DisplayName so that the legend shows the right label
    figure,hold on
    for iCluster = 1:nClusters
        clustIdx = Cluster==uClusters(iCluster);
        plot3(X(clustIdx,1),X(clustIdx,2),X(clustIdx,3),'o','MarkerSize',15,...
           'DisplayName',sprintf('Cluster %i',uClusters(iCluster)));
    end
    
    legend('show');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Nx1 matrix of floating-point values. I wish to get the average
Supose I have a matrix. This matrix is blank except some points that create
Have a matrix report now that has Position, Hours and Wages for a location
I have a simple question: given p points (non-collinear) in R^p i find the
Normally, square matrices are used to transform various points. You have a 4D vector
Possible Duplicate: How can I change the values of multiple points in a matrix?
I have created the code to perform a mapping of points from one vector
I have a set of points (with unknow coordinates) and the distance matrix. I
I have a matrix having around 1000 geospatial points(Longitude, Latitude) and i am trying
I have matrix (a) with (1:10),<10 x 1> double. I would like to copy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.