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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:25:35+00:00 2026-06-13T21:25:35+00:00

I have a matrix that is like the following: a = [10 0; 12

  • 0

I have a matrix that is like the following:

a = [10 0; 12 5; 10 0; 12 0; 15 0; 15 2];
a =

10     0
12     5
10     0
12     0
15     0
15     2

I am looking to create a new matrix which find and replaces the zeros with a value that is dependent on the first column’s value. The key is this matrix:

Key =

10   100
12   200
15   300

If the value is already greater than zero in the first column I would like to leave it. The output would look like this:

Output =

10   100
12     5
10   100
12   200
15   300
15     2
  • 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-13T21:25:36+00:00Added an answer on June 13, 2026 at 9:25 pm

    You can do it in one line using logical indexing smartly:

    a(~a(:,2),2)=arrayfun(@(x)Key(Key(:,1)==x,2),a(~a(:,2),1))
    
    %a =    
    %    10   100
    %    12     5
    %    10   100
    %    12   200
    %    15   300
    %    15     2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix in R that I would like to take a single
I have a vector, v3, that looks like this: v3 <- matrix(c(1,1,3,3,2,2, 2,3,1,2,3,1, 3,2,2,1,1,3),
Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat
I have this following numpy matrix that I want to sort in ascending order
I have a string like the following rotate(32) translate(0,-284.35468),translate(8545,84) matrix(d,f,g,s,g) translate(-58,88) Each function can
I have the following sparse matrix that contains O(N) elements boost::numeric::ublas::compressed_matrix<int> adjacency (N, N);
i have a text file that holds a 2-dimensional matrix. it looks like the
I have a matrix like the following (arbitrary cols/rows): 1 0 0 0 0
I am looking to apply an IF statement to a matrix like the following:
I have data like the following matrix: A = [2 5 10 4 10;

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.