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

  • Home
  • SEARCH
  • 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 8334507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:22:43+00:00 2026-06-09T03:22:43+00:00

Matlab is able to distinguish between ‘proper’ matrix multiplication and element-wise matrix multiplication with

  • 0

Matlab is able to distinguish between ‘proper’ matrix multiplication and element-wise matrix multiplication with different operators, so that the former is done as A * B and the latter as A .* B. This is pretty convenient and I was wondering if there was a way to achieve the same thing in C++ for a custom matrix class (and likewise for ./ and .^). That is, I was wondering if it is possible, through defining macros or any other method, to have something like the following actually compile:

MyMatrix A(2,3), B(2,3), C(2,3); //These are 2x3 matrices for the sake of concreteness
C = A .* B; //Similarly for ./, .^

I tried doing this with some simple function #defines and couldn’t get it to work, so I figured I’d put it to SO. I can accept ‘near misses’, i.e. if .* can’t work but somehow :* can, good enough. NB, I’m specifically looking for operators–of course, this behavior can be accomplished with functions in the obvious way but Matlab-like operators would be pretty convenient.

  • 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-09T03:22:45+00:00Added an answer on June 9, 2026 at 3:22 am

    Not that I’m really suggesting this be done (it’s an abomination). You could, say, create a small wrapper class, that when multiplied by a matrix performs an elementwise multiplication. Then give the matrix class a element_wise() method, which returns such a wrapper. Then, you cold “create” operators _*, _/, etc:

    #define _ .element_wise()
    
    A = B _* C; // really B.element_wise() * C
    

    Or keep the preprocessor out of it, by giving each matrix such a wrapper at construction and calling it _, thus allowing:

    A = B ._* C;
    B = A ._/ C;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Matlab script consisting of several cells that should all be able
I have some code that plots triangles in MATLAB. I need to be able
Matlab documentation states that it is possible to replace the Nth occurrence of the
In MATLAB, how do you write a matrix into an image of EPS format?
I am able to create a 3D cone in MATLAB, but: does anyone know
I'm writing a java package that will be called by another language (matlab). If
I have a matlab function and I was able to run it from command
I have one license of Matlab on my computer. I want to be able
I have GUI in Matlab that I have made using the Programmatic approach. It
Since MATLAB does not provide self-reference , what is the actual difference between 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.