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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:42:37+00:00 2026-05-25T00:42:37+00:00

I have data in two columns that looks as follows: A B 1,265848208 3

  • 0

I have data in two columns that looks as follows:

A               B

1,265848208     3
-0,608043611    0
-0,285735893    0
0,006895134     7
0               7
-0,004526196    7
0,176326617     10
-0,159688071    2
0,22439945      2
-0,991045044    1
0,178022324     1
-0,270967397    4
0,285849994     4
1,881705539     23
1,057184204     10
NaN             10

For all unique values in B I want to extract the corresponding value in column A and move it to a new matrix. I’m looking to then compute the mean of all the corresponding values in A and use as a dependent variable (weighted by no of observations per value in B) in a regression with the common value of B being the independent variable to reduce noise. Any help would on how to do this in Matlab (except running the regression) would be great!

Thanks

Oscar

  • 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-25T00:42:37+00:00Added an answer on May 25, 2026 at 12:42 am

    Here is an efficient solution:

    X = [
        1.265848208     3
        -0.608043611    0
        -0.285735893    0
        0.006895134     7
        0               7
        -0.004526196    7
        0.176326617     10
        -0.159688071    2
        0.22439945      2
        -0.991045044    1
        0.178022324     1
        -0.270967397    4
        0.285849994     4
        1.881705539     23
        1.057184204     10
        NaN             10
    ];
    
    %# unique values in B, and their indices
    [valB,~,subs] = unique(X(:,2));
    
    %# values of A for each unique number in B (cellarray)
    valA = accumarray(subs, X(:,1), [], @(x) {x});
    
    %# mean of each group
    meanValA = cellfun(@nanmean, valA)
    
    %# perform regression here...
    

    The result:

    %# B values, mean of corresponding values in A, number of A values
    >> [valB meanValA cellfun(@numel,valA)]
    ans =
                0     -0.44689            2
                1     -0.40651            2
                2     0.032356            2
                3       1.2658            1
                4    0.0074413            2
                7   0.00078965            3
               10      0.61676            3
               23       1.8817            1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame that looks like this, with two key columns and
I have ListView that uses a GridView to display several columns of data. Two
I have a .dat file that contains two columns of numbers so it looks
I have two data frames with two columns each. The first column is timestamps
I have a data frame with two columns. First column contains categories such as
If I have a data capture form with either tapstrips and or two columns
I have some data I am querying. The table is composed of two columns
I have two columns in a data frame, and I have been able to
I have two columns. ColA and ColB contains char(10) with data 20090520 and 20090521.
I have a databound listbox which is actually displaying two columns of data. It

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.