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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:04:09+00:00 2026-06-18T05:04:09+00:00

I have two matrices in matlab, > IRwindow = > > **183** 171 150

  • 0

I have two matrices in matlab,

> IRwindow =
> 
>   **183**  171  150  125  137
    138  167  184  173  152
    105  114  141  167  185  
    148  113  105  115  141  
    186  183  147  112  105
> 
> ILwindow =
> 
>   **201**  170  165  177  203
    181  174  167  169  189 
    154  150  156  168  181 
    187  175  158  131  144 
    173  186  183  167  141

I want to subtract these two matrices element-wise and get the result; for example for first element (183 – 201= -18 ) BUT the output for this element gives zero. the outcome result will be as below:

> IRwindow - ILwindow

 ans =

     **0**    1    0    0    0
     0    0   17    4    0
     0    0    0    0    4
     0    0    0    0    0    
     13    0    0    0    0

how could I keep the real results? without getting zero for negatives in my result-matrix

  • 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-18T05:04:11+00:00Added an answer on June 18, 2026 at 5:04 am

    Run the following example code:

    %# Create random matrices
    X = randi(100, 5, 5);
    Y = randi(100, 5, 5);
    
    %# Convert to strictly non-negative format
    X = uint8(X);
    Y = uint8(Y);
    
    %# Perform subtractions
    A = X - Y;
    
    %# Convert to double format
    X = double(X);
    Y = double(Y);
    
    %# Perform subtraction
    B = X - Y;
    

    For a given sample run:

    A =
    
        0   15   36    0    0
        0    0    0    0    3
        0    0    0   25    0
       13    0   15    0    0
        0   49    0    0   14
    

    while:

    B =
    
        -8    15    36    -4   -65
         0   -47   -45   -11     3
       -18   -17   -11    25   -52
        13   -53    15   -15    -1
       -35    49   -47    -8    14
    

    You will notice that all the negative numbers in A have been replaced by 0, while the negative numbers in B are displayed correctly.

    Stated simply: if you use a numerical format that is not able to store negative numbers, then Matlab truncates at 0. The solution is to convert to a format that is able to accomodate “real” numbers (or a close approximation thereof) such as double, or perhaps in your case one of the int formats may be more appropriate, such as int8, int16, int32 or int64.

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

Sidebar

Related Questions

I have two matrices in Matlab: q = [3 4 5]; w = [5
I have two matrices in MATLAB lets say arr1 and arr2 of size 1000*1000
I have two matrices like the following ones: '01/01/2010' 1 '02/01/2010' 2 '03/01/2010' 3
I have two matrices of different sizes. Let's just define matrix {a} as a(1:10)
I have two matrices. The first contains values, and the second contains names corresponding
I have two matrices a and b (with equal number of columns). I want
I have two matrices A and B , both of which are Nx3 matrices.
lets say I have two matrices, of a different size: a = zeros(1,100); b
In short: I have two matrices (or arrays): import numpy block_1 = numpy.matrix([[ 0,
Hi I need to plot a boxplot in R. I have two matrices a

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.