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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:28:40+00:00 2026-05-27T21:28:40+00:00

For a matrix A (4 rows, 1000 columns). I want to group the columns

  • 0

For a matrix A (4 rows, 1000 columns). I want to group the columns of the matrix A which have the same value for the third line. so I must have sub matrix with a third row that contains the same value.

for example:

if:

A =

     1     4     5     2     2     2     2     1     1     5
     1     4     5     4     4     2     2     4     5     2
     3     3     3     3     4     1     3     5     3     4
     4     5     5     5     4     1     5     5     5     5

then

A1 =

     1     4     5     2     2     1
     1     4     5     4     2     5
     3     3     3     3     3     3
     4     5     5     5     5     5

A2 =

     2     5
     4     2
     4     4
     4     5

A3 =

     2
     2
     1
     1

the result can be in the form of a cell.

  • 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-27T21:28:41+00:00Added an answer on May 27, 2026 at 9:28 pm

    You can make the assignment in a single line using ACCUMARRAY:

    A = [1     4     5     2     2     2     2     1     1     5;
         1     4     5     4     4     2     2     4     5     2;
         3     3     3     3     4     1     3     5     3     4;
         4     5     5     5     4     1     5     5     5     5
         ];
    
    out = accumarray(A(3,:)', (1:size(A,2)), [], @(x){A(:,x)} );
    

    With this, out{i} contains all columns of A where the third row of A equals i (and empty in case there is no valid column).

    If you want out{i} to contain columns corresponding to the i-th smallest unique value in the third row of A, you can use GRP2IDX from the statistics toolbox first:

    [idx,correspondingEntryInA] = grp2idx(A(3,:)'); %'#
    out = accumarray(idx, (1:size(A,2)), [], @(x){A(:,x)} );
    

    Here, out{i} contains the columns corresponding to correspondingEntryInA(i).

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

Sidebar

Related Questions

just a quick question, if I have a matrix has n rows and m
A simple 2 dimensional array allows swapping rows (or columns) in a matrix in
Using NumPy , a matrix A has n rows and m columns, and I
I have two method : template <class T> Matrix<T>::Matrix(int rows, int cols, T* data)
Writing an MxN matrix ( M rows, N columns ) to a CSV file:
Matrix A: 10 rows, 50 columns a1 a2 a3 .... b1 b2 b3 ....
I have a very large matrix (216 rows, 31286 cols) of doubles. For reasons
Given a matrix with 25 rows and 80 columns but with the attributes its
A matrix has m rows and n columns (n being a number not exceeding
How can I generate a random matrix with more rows than columns? For example,

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.