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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:12:17+00:00 2026-06-11T21:12:17+00:00

I need to transpose a vector into a 2D matrix according to a group

  • 0

I need to transpose a vector into a 2D matrix according to a group of values that are equal in another column of a matrix. For example:

1 x1
1 x2
1 x3
1 x4
2 x5
2 x6
2 x7
2 x8

Should look like:

x1 x2 x3 x4;
x5 x6 x7 x8;

This is the same procedure you would do in SAS using proc tabulate. Reshape didn’t work for me because it doesn’t transpose it, and tried permute with no luck either. Is there any built in command that does this besides having to program it in using find, transpose, and vertcat?

  • 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-11T21:12:18+00:00Added an answer on June 11, 2026 at 9:12 pm

    If for some reason you want to avoid reshape, although the solution in comments will work, you can use sub2ind to get the linear indices of the new matrix V, given that your first column will always provide the new line sub:

    X = [[1,1,1,1,2,2,2,2]' (1:8)'];
    subs = X(:,1);
    
    M = length(unique(subs)); % count unique ids
    N = length(X)./M; % Problem assumption: M sets of size N (MxN=length(X))
    
    V = zeros(M, N);
    i = sub2ind([M, N], subs, repmat(1:N,1,M)');
    V(i) = X(:,2);
    

    The above, according to your specs, will work as long as there is an equal number of unique elements in X, so you can form an MxN matrix.

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

Sidebar

Related Questions

I have a variable length array that I need to transpose into a list
I need to obtain a matrix vvT formed by a column vector v .
I need transpose an array from rows into cols and cols into rows def
Is It possible to Transpose Unlimited rows into column through PIVOT in SQL Server?
I have some Perl code that I need to transpose in Java. In this
Need help with a query that I wrote: I have three tables Company id
Need to set some attributes of button. For example Checked. I guess it is
I want to transpose a matrix, its a very easy task but its not
I tried to find the eigenvalues of a matrix multiplied by its transpose but
I have a set of data (26250) on one column, but I need them

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.