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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:16:30+00:00 2026-06-17T16:16:30+00:00

I have two column vectors. The first column vector is several thousand data points

  • 0

I have two column vectors.

The first column vector is several thousand data points long, and I need to take the median from the first forty items, and then the median from the next forty, and so on.

The second column vector contains a group ID (from 1 to 3).

My goal is to end up with a bunch of median calculations and to have them sorted by group. I am very unsure of how to go about this in MATLAB.

  • 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-17T16:16:31+00:00Added an answer on June 17, 2026 at 4:16 pm

    Here’s a bit of code to get you started.

    If you have both vectors in one named variable, and the number of columns is exactly divisible by 40, do this:

    % column 1 = data, column 2 = groupID
    test = rand(400,2);
    
    % compute medians of data
    medians = median( reshape(test(:,1), 40,[]) );
    
    % make each entry correspond to the correct groupID
    medians = repmat(medians, 40,1);
    medians = medians(:);
    

    If your data is NOT exactly divisible by 40, use a simple loop:

    N = 40;
    
    test = rand(10*N+4,2);
    
    n = 1;
    medians = zeros( ceil(size(test,1)/N), 1 );
    for ii = 1:numel(medians)
        if n+N-1 > size(test,1)
            medians(ii) = median(test(n:end,1));
        else
            medians(ii) = median(test(n:n+N-1,1));
        end
        n = n+N;
    end
    

    and replicate as before if necessary.

    Adjustments to this code for if you have the groupID in a separate variable, or how to sort these things according to groupID, are pretty straightforward.

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

Sidebar

Related Questions

I have two tables and their only difference is one column is missing from
I have two column vectors [a b] and [c d]. I want to select
I have an AxB matrix and two binary column vectors, Ax1 and Bx1 in
Imagine a set of data with given x-values (as a column vector) and several
I have a very large two dimensional array and I need to compute vector
I have a two column layout: http://jsfiddle.net/KqQ42/1/ Now I would like that the left
I have a two column site layout that has the content of the left
I have a two column dataframe in R and i want to add a
I have a two-column primary key on a table. I have attempted to alter
I have TWO tables 1) column 2) row COLUMN TABLE COLumnID ---------------- 1 2

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.