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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:33:43+00:00 2026-05-28T20:33:43+00:00

I am trying to find a nice solution for the following situation: I have

  • 0

I am trying to find a nice solution for the following situation:

I have a class:

classdef SomeClass < handle

    properties (Access = private)
        x
    end

    methods
        function x = getX(this)
            x = this.x;
        end
    end
end

Let x – some data array.
Do I have a possibility to address some element of array like I’d make it in struct:

struct.x(5)

Or do I always have to do like this?:

myClassObj = SomeClass();
x = myClassObj.getX();
x(5)

or create some func getXAt?

  • 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-28T20:33:43+00:00Added an answer on May 28, 2026 at 8:33 pm

    Yes. Addressing like that is the normal behavior of a property in a Matlab object. You can just expose the property for reading instead of making it fully private.

    classdef SomeClass < handle
    
        properties (SetAccess=private)
            x
        end
    
        methods
            function obj = SomeClass(x)
                obj.x = x;
            end
        end
    end
    

    Then you can address it like a field on a struct.

    >> sc = SomeClass(1:7);
    >> sc.x(5)
    ans =
         5
    >> 
    

    There’s no need in Matlab to always make your own accessor functions like you would in Java. You can independently control the read and write access of a property using attributes on it. If you want more complex property access logic, you can define getters and setters using the special function out = get.x(obj) syntax, and their behavior will apply to property access done with the obj.x syntax.

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

Sidebar

Related Questions

I am trying to find a nice solution to concatenate and compress javascript and
I have been trying to find a solution to this with no avail. The
I am trying to find an optimal solution for the following problem: there is
Been trying to find this online for a while now. I have a SDL_Surface
I'm trying to find the best server architecture solution to deploy monthly updates to
I have a website with a huge htaccess, but I'm trying to find a
It's nice to find such a useful site with genius members. I have been
I'm trying to find a nice library for user friendly exception handling for unhandled
I am trying to find a nice way to find all events of type
Im trying to find out a good JavaScript library that can create a nice

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.