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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:03:11+00:00 2026-05-27T13:03:11+00:00

I am writing a wrapper for plot that automates some tasks that I find

  • 0

I am writing a wrapper for plot that automates some tasks that I find myself doing frequently.

An example code snippet might look like

function myplot(x,y,varargin)
    plot(x,y,varargin{:})
    xlabel('x axis')
    ylabel('y axis')
end

I’m using Matlab’s varargin to pass additional arguments to plot. However, I find that I might want to pass my own optional arguments in varargin. For example, I might want to write something like

>> myplot(1:10, 1:10, 'r', 'LineWidth', 2, 'legend', {'Series 1'})

to have the function automatically include a legend in the plot – that is, I want to be able to mix my own keyword arguments with the ones that you can supply to plot. Short of writing a full parser for my varargs, is there a way to do this simply and reusably in Matlab?

I’ve tried to use the inputParser object, but that would require me to manually add every possible additional argument to plot (and a default for it) which doesn’t seem ideal.

  • 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-27T13:03:12+00:00Added an answer on May 27, 2026 at 1:03 pm

    inputParser may still be the best choice. You can construct the object for your additional arguments, and lump all the parameterName/parameterValue pairs that you want to pass to plot into Unmatched.

    function myplot(x,y,varargin)
    
        parserObj = inputParser;
        parserObj.KeepUnmatched = true;
        parserObj.AddParamValue('legend',false); 
        %# and some more of your special arguments
    
        parserObj.parse(varargin);
    
        %# your inputs are in Results
        myArguments = parserObj.Results;
    
        %# plot's arguments are unmatched
        tmp = [fieldnames(parserObj.Unmatched),struct2cell(parserObj.Unmatched)];
        plotArgs = reshape(tmp',[],1)'; 
    
    
        plot(x,y,plotArgs{:})
        xlabel('x axis')
        ylabel('y axis')
    
        if myArguments.legend
           %# add your legend
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a wrapper application that will be used to provide an abstraction layer
I'm writing a wrapper to a function that takes varargin as its inputs. I
I'm writing a wrapper program that loads Winamp input plugins. I've got it working
I'm writing a little wrapper for an application that uses files as arguments. The
Hi I writing a wrapper in c# and i have some problem. I have
I'm writing a wrapper class around the V8 engine so that eventually I'll be
I'm writing a wrapper that calls a method, and if an exception is thrown,
I am writing a wrapper around C DLL in C++/CLI so that it can
In a project of mine, I'm writing a wrapper for std::vector . I'm doing
I'm writing a wrapper that forks an execv() process. Output from the child is

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.