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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:01:34+00:00 2026-06-14T17:01:34+00:00

Confer the following code: classdef highLowGame methods(Static) function [wonAmount, noGuesses] = run(gambledAmount) noGuesses =

  • 0

Confer the following code:

classdef highLowGame
    methods(Static)
        function [wonAmount, noGuesses] = run(gambledAmount)
            noGuesses = 'something';
            wonAmount = highLowGame.getPayout(gambledAmount, noGuesses); % <---
        end
        function wonAmount = getPayout(gambledAmount, noGuesses)
            wonAmount = 'something';
        end
    end
end

Is there a way to call a static method of the same class (inside a static) method without having to write the class name? Something like “self.getPayout(…)” – in case the class turns out to get to 500 lines and I want to rename it.

  • 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-14T17:01:35+00:00Added an answer on June 14, 2026 at 5:01 pm

    As far as I can tell, “no” with a “but”. In general, you can only specify the static method with the class name. However, you can fake your way around the restriction since MATLAB has feval:

    classdef testStatic
    
        methods (Static)
            function p = getPi()  %this is a static method
                p = 3.14;
            end
        end
    
        methods
            function self = testStatic()
    
                testStatic.getPi  %these are all equivalent
                feval(sprintf('%s.getPi',class(self)))
                feval(sprintf('%s.getPi',mfilename('class')))
            end
        end
    end
    

    Here, class(self) and mfilename both evaluate to ‘testStatic’, so the functions above end up evaluating ‘testStatic.getPi’.

    Or, alteratively, you can write a non-static method, self.callStatic; then always use that. Inside that, just call testStatic.getPi. Then you’ll only need to change that one line.

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

Sidebar

Related Questions

Possible Duplicate: What advantages does using (function(window, document, undefined) { … })(window, document) confer?
I have the following code. How to convert lonlat value to GPS used values
I have a simple RallyComboBox created with the following code: Ext.define('CustomApp', { extend: 'Rally.app.App',
I have the following validation rules to my form: function ValidadeRegistration() { $('#RegistrationForm').validate({ rules:
So I am using the following code to take an existing image, text from
I have a native function, defined in my C++ code, that is called within
I have to following SQL Statement that I want to conver to LINQ Select
With this configuration for some reason Conver function of Custom Converter is not called
I'm trying to debug some legacy Integration Services code, and really want some confirmation
I have some classic asp code that needs converting to asp.net. So far 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.