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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:09:54+00:00 2026-05-27T04:09:54+00:00

The following MATLAB code does not work. I guess it has something to do

  • 0

The following MATLAB code does not work. I guess it has something to do that in the function changer, MATLAB tries to equal the objects A and B and not just setting the values to the same. Any workaround for that?

classdef foo
    %FOO Summary of this class goes here
    %   Detailed explanation goes here

    properties
        A=5
        B=0
    end

    methods
        function changer(obj)
            obj.B=obj.A
        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-27T04:09:55+00:00Added an answer on May 27, 2026 at 4:09 am

    I think the code is actually working fine, just not doing quite what you expect.

    The way you’ve defined it, foo is a value class, so it has value semantics, rather than reference (or handle) semantics. When you execute changer(myobj), MATLAB is creating a copy of myobj with the new value of B and returning it to you. The original myobj remains unchanged. When implementing a value class, you would typically add an output argument to changer in order to be able to further work with this new copy.

    function obj = changer(obj)
    

    If you set foo to be a handle class, by inheriting from handle:

    classdef foo<handle
    

    it will then have reference (or handle) semantics, where the original myobj is modified (you then no longer need the output argument from changer):

    >> myobj = foo;
    >> changer(myobj); % or alternatively myobj.changer
    >> myobj.B
    ans =
         5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose that there is given following matlab code function dp = derp(p) n =
what does following code in MATLAB means? L = bwlabel(B,8) mx= max(max(L)) any ideas?
I have the following matlab code: randarray = gpuArray(rand(N,1)); N = 1000; tic g=0;
I want to vectorize the following MATLAB code. I think it must be simple
What is equivalent pythonic implementation for the following simple piece of code in Matlab.
the code I'm dealing with has loops like the following: bistar = zeros(numdims,numcases); parfor
In the following Matlab code, with nodes N=10 , you will get randomly picked
In the following matlab code, random_numbers = randn(1,1000); j=1; for i=1:length(random_numbers) if random_numbers(i) >
Basically I have 14800x8 matrix that has been extracted from matlab as CSV file
Can somebody explain me what the following bit of code in Matlab is doing?

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.