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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:15:19+00:00 2026-05-24T10:15:19+00:00

I am having a vector y which may have the following form: y =

  • 0

I am having a vector y which may have the following form:

y = [1 1 1 1 2 2 2 2 1 1 3 3 4 5]

And I want to attach a probability to each element within y as it would’ve been generated by a random variable. In this case, the element 1 would have the probability 6/14, the element 2 would have the probability 4/14, the element 3 the value 2/14 and the elements 4 and 5 the value 1/14.

And basically, the result should look like:

prob_y = 1/14 * [6 6 6 6 4 4 4 4 6 6 2 2 1 1]

Is there a way of doing this without any for or while loops?

  • 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-24T10:15:20+00:00Added an answer on May 24, 2026 at 10:15 am

    The unique elements in your input vector can be determined using the UNIQUE function. You can then get the desired output using ARRAYFUN and an anonymous function that checks the number of each unique element in your input vector:

    >> y = [1 1 1 1 2 2 2 2 1 1 3 3 4 5];
    >> prob_y = arrayfun(@(x)length(find(y==x)), unique(y)) / length(y)
    
    prob_y =
    
        0.4286    0.2857    0.1429    0.0714    0.0714
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, which splits up a Vector into a string vector
I wrote a code ( c++,visual studio 2010) which is having a vector, even
I'm having a std::vector with elements of some class ClassA . Additionally I want
I am having problems matching the correct color vector which I use in 'plot'
I have a method to which a vector's iterator is passed. In this method
I'm having a for loop which I would like to convert into parallel_for fnc
i have written a class which implements ListFieldCallBack like, import java.util.Vector; import net.rim.device.api.ui.Graphics; import
I have a class in which I would like to have a static member
Having a vector containing pointers to objects then using the clear function doesn't call
I'm having some trouble reading data from a file into a vector of Orders.

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.