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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:53:47+00:00 2026-05-26T01:53:47+00:00

I have a typical scenario in which there is a Vector X and Vector

  • 0

I have a typical scenario in which there is a Vector X and Vector Y. Vector X contains increasing values, for example X = [1 1 1 2 2 3 4 4 4 4 4]. Vector Y contains real values of same size as X. Im looking to plot Index Vs Y with color change for each different value of X for the corresponding index.

For example, the plot should have color1 for the first 3 values of 1, color2 for the next 2 values of 2, color3 for 1 value 3 and so on.

Can any one help me

  • 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-05-26T01:53:47+00:00Added an answer on May 26, 2026 at 1:53 am

    Building on Laurent’s answer and implementing your “Index vs Y” requirement,

    function color_plot(data_vector, color_vector)
    styles={'ro','g.','bx','kd'};
    hold off;
    for i=unique(color_vector)
        thisIdx=find(color_vector==i);
        thisY=data_vector(color_vector==i);
        thisStyle=styles{mod(i-1,numel(styles))+1}; 
        plot(thisIdx,thisY,thisStyle);
        hold on;
    end
    hold off;
    

    My version also allows arbitrarily large color indices; if you don’t have enough styles defined, it just wraps back around and reuses colors.

    Update note I had to fix a sign above in the calculation oh thisStyle.

    Testing it with

    X = [1 1 1 2 2 3 4 4 4 4 4];
    Y=rand(size(X))
    color_plot(Y,X)
    

    now gives

    enter image description here

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

Sidebar

Related Questions

I was looking at the usage example based on a typical producer-consumer scenario at:
I have this typical scenario. I have a smartclient application built on .net 2.0
I have a typical dev scenario: I have a SQL 2008 database that I
In a typical enterprise scenario with in-house development, you might have dev, staging, and
We have a typical business application with an Outlook-looking Winforms client talking to asmx
I have a typical MVVM scenario: I have a ListBox that is binded to
Typical scenario: a class that a lot of people have worked on. I'd like
In a pretty typical scenario, I have a 'Search' text box on my web
I have a typical scenario that I'm struggling with from a performance standpoint. The
Here's a scenario: I have a java front end (RCP/SWT) app which currently has

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.