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 8639509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:01:26+00:00 2026-06-12T11:01:26+00:00

Along with 3 numeric values the data contains categorical value (0 or 1) and

  • 0

Along with 3 numeric values the data contains categorical value (0 or 1) and would like to display the data using 3D scatter plot. I have tried to write a function to read the data from csv file and create a scatter plot the following way:

function f = ScatterPlotUsers(filename)

    data = ReadCSV(filename);
    x = data(:,2);
    y = data(:,3);
    z = data(:,4);

    size = ones(length(x), 1)*20;
    userType = data(:,5);
    colors = zeros(length(x), 1);

    a = find(userType == 1);
    b = find(userType == 0);
    colors(a,1) = 42; %# color for users type a
    colors(b,1) = 2;  %# color for users type b

    scatter3(x(:),y(:),z(:),size, colors,'filled') 
    view(-60,60);

What I actually wanted to do was to set the colour for a to red and b to blue but no matter the colour values (42 and 2 in example) the colours of dots don’t change.
Does anyone know what is the right way to determine specific colours for several categorical values (in this case only 0 and 1)?

  • 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-12T11:01:27+00:00Added an answer on June 12, 2026 at 11:01 am

    You are doing it right, however, are you sure the colormap entries 42 and 2 refer to red and blue? You could try to give RGB values explicitly:

    colors = zeros(length(x), 3);
    colors(userType == 1, :) = [1 0 0]; %# colour for users type a (red)
    colors(userType == 2, :) = [0 0 1]; %# colour for users type b (blue)
    

    Also, I’d advise you to change the name of the variable size, since size is also a Matlab command; Matlab might be confused about that, and any future readers of your code will certainly be confused about that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sending mail along with embedded image using asp.net I have already used following but
I have an HTML along the following lines: <div class=hiddenClass> // this implies display:none
I would like to allow the user to enter (a non-predetermined amount of) values
I have a numeric field (say num) in table along with pkey. select *
I have an html table that literally has like 30 columns of data, and
I have an input box with a numeric value in it. When the user
I have a type data Value = Int Integer | Float Double | Complex
Along with the Like button, there is a Send button, whose functionality is similar
I have two Activities along with one Application class, and whenever I call my
I am using git along with git flow . Here git flow has a

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.