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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:36:49+00:00 2026-06-14T00:36:49+00:00

I am working on a project in which I need to transform the result

  • 0

I am working on a project in which I need to transform the result matrix to a simpler matrix. More specifically, for each column in matrix, I want to find the maximum value in row and change it to 1, and the rest of the values will be change to 0. I am not sure how to search this question so I decide to post it here.

For example, I have a matrix X:

X = [2 8 4; 7 3 9;1 2 3];
X = 2 8 4
    7 3 9
    1 2 3

and I want to transform this matrix to

X' = 0 1 0
     1 0 1
     0 0 0

I only know how to use for loop to return the maximum value from each row, but I am not sure how to return the position in matrix of that value and convert the rest to zero.

Here is my idea

  1. Create a new same dimension zero matrix first
  2. Find the maximum value in row
  3. Find the position of the maximum value
  4. Assign the value 1 into new matrix at same position
  5. Repeat 2 and 3 by for loop

I am new to Matlab, hope you can help.

Here is one of the result of my program

 2.0680   17.7410    0.8992   -3.0221
 3.6093    7.3443    6.7442    0.9874
-0.9095   -3.3220   -1.4857   -0.0023
-1.1753  -16.7906    0.3672    3.7697
-1.6856   -6.0929   -2.8614    0.5054
 1.0794    3.8352    1.9894    0.1686
-0.4584   -0.3923   -1.2525   -0.4761

And I want this matrix transform to

0 1 0 0
1 0 1 0
0 0 0 0
0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0

So I think the reason why max() not work is becuase I have negative value inside the matrix

Other example which not wotk with max()
Columns 1 through 5

 0.3816   23.2243   19.6435   23.2243   -3.1993
 3.8674    8.0762    6.0563    8.0762    1.8475
-0.4442   -4.0758   -3.4244   -4.0758    0.2073
 0.7639  -22.3618  -19.1365  -22.3618    3.9892
-1.8128   -6.4602   -5.1011   -6.4602   -0.4536
 0.2954    3.5886    3.1529    3.5886   -0.1403
-0.3723    0.8057    0.6607    0.8057   -0.5173

Columns 5 through 10

 1.4814   19.6435    3.3100   23.2243    1.4814
 7.0255    6.0563    6.5251    8.0762    7.0255
-1.1483   -3.4244   -1.1448   -4.0758   -1.1483
-0.7784  -19.1365   -2.3904  -22.3618   -0.7784
-3.8880   -5.1011   -3.7437   -6.4602   -3.8880
 1.0289    3.1529    0.7994    3.5886    1.0289
-0.3723    0.8057    0.6607    0.8057   -0.5173

Columns 11 through 15

 21.3957   19.6435    1.4814    0.3816   -3.1993
 8.5765    6.0563    7.0255    3.8674    1.8475
-4.0793   -3.4244   -1.1483   -0.4442    0.2073
-20.7498  -19.1365   -0.7784    0.7639    3.9892
-6.6046   -5.1011   -3.8880   -1.8128   -0.4536
 3.8181    3.1529    1.0289    0.2954   -0.1403
 0.4994    0.6607   -0.5829   -0.3723   -0.5173

Columns 16 through 20

  -1.7736    9.5635   20.0251    1.8072    0.3816
   1.6114    7.0884    9.9237    3.6313    3.8674
  -0.0058   -2.3835   -3.8685   -0.6572   -0.4442
   2.1941   -8.7540  -18.3726   -1.0312    0.7639
  -0.5815   -4.5430   -6.9138   -1.9407   -1.8128
   0.1232    2.4470    3.4483    0.5589    0.2954
  -0.3588   -0.2377    0.2884   -0.2138   -0.3723

The correct answer is use bsxfun(@eq, output, max(output))

  • 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-14T00:36:50+00:00Added an answer on June 14, 2026 at 12:36 am

    Not entirely sure what you mean, but does

    >> bsxfun(@eq, X, max(X,[],2))  % maximum per row
    ans =
         0     1     0
         0     0     1
         0     0     1
    

    Come close? If you mean the maximum per column, then just use

    >> bsxfun(@eq, X, max(X)) % maximum per column
    ans =
         0     1     0
         1     0     1
         0     0     0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project in which I need to download and parse
I am working on a project in which I need to generate 8 random
I'm working on a project in which I need to process a huge amount
I am working on a project in which I need to change the time
Currently we are working on a project in which we need to come up
Currently I am working with the project in which I need to parse complex
I am working on a homework project in which we need to generate a
I'm working on using a project which uses jQuery, and I need to dynamically
Can anyone help me find an up-to-date, working ATL project which has a main
Im working on a small project which I need to send a couple 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.