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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:54:12+00:00 2026-05-20T11:54:12+00:00

I have a mesh grid defined as [X, Y, Z] = meshgrid(-100:100, -100:100, 25);

  • 0

I have a mesh grid defined as

[X, Y, Z] = meshgrid(-100:100, -100:100, 25); % z will have more values later

and two shapes (ovals, in this case):

x_offset_1 = 40;
x_offset_2 = -x_offset_1;
o1 = ((X-x_offset_1).^2./(2*Z).^2+Y.^2./Z.^2 <= 1);
o2 = ((X-x_offset_2).^2./(2*Z).^2+Y.^2./Z.^2 <= 1);

Now, I want to find all points that are nonzero in either oval. I tried

union = o1+o2;

but since I simply add them, the overlapping region will have a value of 2 instead of the desired 1.

How can I set all nonzero entries in the matrix to 1, regardless of their previous value?

(I tried normalized_union = union./union;, but then I end up with NaN in all 0 elements because I’m dividing by zero…)

  • 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-05-20T11:54:12+00:00Added an answer on May 20, 2026 at 11:54 am

    Simplest solution: A=A~=0;, where A is your matrix.

    This just performs a logical operation that checks if each element is zero. So it returns 1 if the element is non-zero and 0 if it is zero.

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

Sidebar

Related Questions

I have a two dimensional polygon mesh made of connected triangles represented like this:
I have this mesh class which is spread out over two files (mesh.h and
I have an irregular mesh which is described by two variables - a faces
I have this object I'm loading with THREE.objLoader and then create a mesh with
I have a few 1000s triangles connected in a 2D mesh grid. It represents
I have a terrain mesh stored in a VBO. The mesh is a grid
This topic has been discussed but I've been unsuccessful. I have a basic mesh
I have a mesh in a form like this . with a list of
I have two classes, Mesh and MeshList. I want MeshList to have a function
I have a terrain mesh where just the Z value for each vertex needs

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.