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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:54:38+00:00 2026-05-16T22:54:38+00:00

I have a custom function which returns either 0 or 1 depending on two

  • 0

I have a custom function which returns either 0 or 1 depending on two given inputs:

function val = myFunction(val1, val2)

  % logic to determine if val=1 or val=0

end

How can I create a contour plot of the function over the x,y coordinates generated by the following meshgrid?

meshgrid(0:.5:3, 0:.5:3);

This plot will just simply display where the function is 0 or 1 on the contour map.

  • 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-16T22:54:38+00:00Added an answer on May 16, 2026 at 10:54 pm

    If your function myFunction is not designed to handle matrix inputs, then you can use the function ARRAYFUN to apply it to all the corresponding entries of x and y:

    [x,y] = meshgrid(0:0.5:3);      %# Create a mesh of x and y points
    z = arrayfun(@myFunction,x,y);  %# Compute z (same size as x and y)
    

    Then you could use the function CONTOUR to generate a contour plot for the above data. Since your z data only has 2 different values, it would probably make sense for you to only plot one contour level (which would be at a value of 0.5, halfway between your two values). You might also want to instead use the function CONTOURF, which produces color-filled contours that will clearly show where the ones and zeroes are:

    contourf(x,y,z,1);  %# Plots 1 contour level, filling the area on either
                        %#   side with different color
    

    NOTE: Since you are plotting data that only has ones and zeroes, plotting contours may not be the best way to visualize it. I would instead use something like the function IMAGESC, like so:

    imagesc(x(1,:),y(:,1),z);
    

    Keep in mind the y-axis in this plot will be reversed relative to the plot generated by CONTOURF.

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

Sidebar

Related Questions

I have a custom PHP function which executes a stored procedure and returns an
I have a function which takes a custom struct as the argument. how can
I have a load of php templates which uses a custom translate function __,
I have a webform, and a custom validation function. Which both work fine. But
I have an array filled with instances of a custom class which contains two
I have a function, which returns a Task to do anything with that. I
Iam calling a PHP custom function with different parameters which returns a different arrays
I have a custom query which eventually returns a list of objects. I need
I have created a custom function and I am getting this error. I dont
I have custom validation rule: public function customRule($check) { } Inside this rule I

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.