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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:40:03+00:00 2026-05-25T02:40:03+00:00

Suppose I have a myClass < handle with property A . If I create

  • 0

Suppose I have a myClass < handle with property A. If I create an instance of myClass, say myObj, and pass myObj.A to a function, say function myFunc(val), is it possible within myFunc to see that the val passed to it is a property of myObj?

EDIT: For context:

I’m writing an API (in a sense) to interface with Arduino hardware for my research lab. The overarching class is called Vehicle, with properties PinManager < handle, TelemCollector < handle, and various Device < handles. It also has methods to do things like runMotor(), getAltitude(), etc. I have a method TelemCollector.telemFetch() which is the callback for a timer event; I would like TelemCollector.telemFetch() to be able to access Vehicle methods (namely getAltitude()); naively I would just make Vehicle a property of TelemCollector to access those methods. I was hoping to not have to do this.

EDIT2: Sample code snippet of what I’m trying to accomplish:

classdef Vehicle < handle
    properties
        PinManager
        TelemCollector
        Devices
    end
    methods
        function obj = Vehicle(PM, TC, D)
            obj.TC = TelemCollector();
            obj.PM = PinManager();
            obj.Devices = D();
        end 
        function val = getAltitude(obj)
            %# read altitude from a connected Device
        end
        function val = getSpeed(obj)
            %# read speed from connected Device
        end
    end
 end

 classdef TelemCollector < handle
     properties
         %# ...
     end
     methods
         function fetchTelem(obj)
             %# do getAltitude(), getSpeed(), etc, here.. but I want to access
             %# Vehicle.getAltitude() and Vehicle.getSpeed() somehow!
         end
     end
 end
  • 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-25T02:40:03+00:00Added an answer on May 25, 2026 at 2:40 am

    For all I know, no.

    For example if myObj.A is a double, myFunc will just be passed the value it contains and there will be no reference to the object. If you were calling myFunc(somevariable) where somevariable was really the name of a variable and not an expression, then calling inputname(1) inside of myFunc would give you the string ‘somevariable’, but since you are referring to a property of a class, this is too complicated for MATLAB and inputname(1) just returns '' (tested with MATLAB R2011a).

    Update: Why do you need to know this anyhow? If your interfaces are cleanly designed, you should probably not have to do this kind of thing. Or are you trying to work around someone else’s bug/bad design? Depending on your application you could think of some kind of very dirty hack involving dbstack, trying to find out which m-file called your function, read the appropriate line of code from the .m file, parse it and then access the object using evalin('caller',...) … but I doubt that’s a good idea ;-).

    Edit in response to context you provided:

    Can’t you just redefine your Timer callback to hand over the “Vehicle” object as well? i.e.

    set(yourtimer_handle,'TimerFcn',{@fetchTelem,vehicle_handle});
    

    means that whenever the callback timer calls the function TelemCollector.fetchTelem(), it hands over vehicle_handle as a third argument as described in the docu. This works in conjunction with a changed function head

    function fetchTelem(obj, event, vehicle_handle)
    

    where you can replace event by ~ in newer MATLAB versions if you don’t need it.

    Could that work?

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

Sidebar

Related Questions

Suppose I have a class like this: function myClass(q) { this.someFunction = function(e) {
Suppose I have JavaScript code like myClass = function(){ function doSomething(){ alert(this); // this1
Suppose, i have class, define('property', 'test'); class myClass { public $test; } $obj=new myClass;
Suppose I have the following class: classdef myClass < handle properties A = [10
Suppose I have the class: class MyClass { protected $protected; private $_private; public function
Suppose I have a template class MyClass. Is it possible to store the type
Suppose I have simple class like: class MyClass { private $_prop; public function getProp()
Suppose I have a generic class called MyClass<T> how can I create a JavascriptConverter
Suppose I have a class public class MyClass { private Set<String> set = new
Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key=whatever Text=foo\nbar /> </Window.Resources> Obviously

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.