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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:22:48+00:00 2026-06-15T08:22:48+00:00

We have a matrix: Index: 1 2 3 4 5 6 Elements: 0 2

  • 0

We have a matrix:

Index:    1 2 3 4 5 6 

Elements:
          0 2 0 5 9 8 
          1 0 5 0 5 4
          0 1 0 0 6 0 

Is it possible to be sorted by size of different elements per column?
Result should be like this:

  Index:     5 2 6 1 3 4 

  Elements:
             9 2 8 0 0 5 
             5 0 4 1 5 0
             6 1 0 0 0 0 

Thank you in advance.

  • 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-15T08:22:49+00:00Added an answer on June 15, 2026 at 8:22 am

    With “length” and “unique” functions you can retrieve the number of different values of each column (including zero), for example:

    for n=1:size(a,2)
      b(n)=length(unique(a(:,n)));
    end
    

    If you want to ignore zeros you could use

    b(n)=sum(unique(a(:,n)) ~= 0);
    

    Which gives an array with the number of different elements of each column:

    b =    1     2     1     1     3     2
    

    Then you can sort this array and use the ordered indexes to sort your matrix:

    [~, index]=sort(b, 'descend');
    result = a(:, index)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So let's say I have a matrix, mdat and I only know the index
I have matrix (a) with (1:10),<10 x 1> double. I would like to copy
I have a matrix of objects that contains data in this form: name A,2,name
I have a lot of elements in a matrix and when I access them
I have 100 models (matrices), where each matrix's size is 4X3. Each of the
Or should I use a different hammer to fix this problem. I've got a
I have a large matrix from which I would like to gather a collection
So i have this program that should solve a futoshiki puzzle in C wich
How can I create an index-matrix that specifies which elements of a matrix to
I would like to write variable f into certain elements ( index ) of

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.