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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:40:58+00:00 2026-06-08T10:40:58+00:00

I have Matrix A: A= [ 1 1 0 2 2 2 2 0

  • 0

I have Matrix A:

A= [ 1 1 0 2 2 2 2 0 0 3 3 0 0;
     0 1 1 0 0 2 2 2 2 3 3 0 0 ];

and I want to make another matrix B, so that this matrix contains the number of value occurences of the original matrix A: ie each iith row of B contains how many times ii occurs in the corresponding columns of A. The number 0 may be ignored.

For example: in the 2nd column of A, only the number 1 occurs, to be specific two times –> hence B(1,2) = 2 and B(other,2) = 0.

For my example matrix A, the output should be

Res = [ 1 2 1 0 0 0 0 0 0 0 0 0 0;
        0 0 0 1 1 2 2 1 1 0 0 0 0;
        0 0 0 0 0 0 0 0 0 2 2 0 0 ];
  • 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-08T10:41:00+00:00Added an answer on June 8, 2026 at 10:41 am

    You can use

    A= [ 1 1 0 2 2 2 2 0 0 3 3 0 0;
         0 1 1 0 0 2 2 2 2 3 3 0 0 ];
    
    
    cell2mat(arrayfun(@(b) sum(A == b),nonzeros(unique(A)), 'UniformOutput', false))
    

    This results in

    ans =
    
         1     2     1     0     0     0     0     0     0     0     0     0     0
         0     0     0     1     1     2     2     1     1     0     0     0     0
         0     0     0     0     0     0     0     0     0     2     2     0     0
    

    If, as asked in the comments, the matrix a has three dimensions, you need to sum the result along the third dimension:

    sum(cell2mat(arrayfun(@(b) sum(A == b,1),nonzeros(unique(A)), 'UniformOutput', false)),3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following numpy matrix that I want to sort in ascending order
I have this matrix of size 10000 by 1. I want to remove some
so we have this matrix a=[1;2;3] and we want to multiply it by itself
I have one column matrix with n rows. I want difference between row 2
I have a textfile that I am I want to make into a list.
I have created a SSRS 2008 report.I have created a matrix.I want to make
Imagine that I have a matrix of 2x2 or 3x3 pictures and I want
I have a matrix A which I want to convert into a data.frame of
I have a matrix A consisting of 200 vectors of size d. I want
I want to store the TF-IDF matrix so I don't have to recalculate 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.