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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:47:02+00:00 2026-06-07T08:47:02+00:00

I am struggling to understand why my instance variables not being saved. Whenever I

  • 0

I am struggling to understand why my instance variables not being saved. Whenever I make a change to CurrentSettings, it does not appear next time I call another function. Basically it does not save and reverts to 0s after each function.

classdef laserControl
%LASERCONTROL This module is designed to control the laser unit. 
%   It can set the filter position, open and close the shutter and turn
%   on/off the laser.
%
%%%%%%%%%%PORT LISTINGS%%%%%%%%%%%
%The set filter command is on port0
%The set shutter is in port1
%Laser 1 on port2
%Laser 2 on port3
%The filter digits are on ports 8-15 (the are on the second box)

properties%(GetAccess = 'public', SetAccess = 'private')
    laserPorts; %The #'s of the output ports
    currentSettings; %Current high/low settings
    dio;
end

methods

    %Constructor
    %Opens the connection with the digital outputs
    %Make sure to close the connection when finished
    function Lobj = laserControl()
        %Setup the laser
        Lobj.laserPorts = [0:3 8:15];% 8:15
        Lobj.currentSettings = zeros(1, length(Lobj.laserPorts));
        %Make connection and reset values
        Lobj.dio = digitalio('nidaq','Dev1');
        addline(Lobj.dio, Lobj.laserPorts, 'out');
        putvalue(Lobj.dio, Lobj.currentSettings);
    end

    %Closes the connection to the digital output
    function obj = CloseConnection(obj)
        putvalue(obj.dio, zeros(1, length(obj.currentSettings)));
        delete(obj.dio);
        clear obj.dio;
    end


    %Sets the position of the filter.
    %positionValue - the integer amount for the position, cannot be
    %larger than 150, as regulated by the box.
    %The set filter command is on port0
    %The filter digits are on ports 8-15 (the are on the second box)
    function obj = SetFilterPosition(obj, positionValue)
        if 0 <= positionValue && positionValue < 150
            binaryDigit = de2bi(positionValue); %Convert it to binary form
            %LaserOn OldSettings NewValue ExtraZeros
            obj()
            obj.currentSettings()
            obj.currentSettings = [1 obj.currentSettings(1, 2:4) binaryDigit...
                zeros(1, 8 - length(binaryDigit))];
            putvalue(obj.dio, obj.currentSettings);
        else
            display('Error setting the filer: Value invalid');
        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-06-07T08:47:04+00:00Added an answer on June 7, 2026 at 8:47 am

    Because your class does not inherit from handle, you’ve written a “value”-type class – in other words, when you make changes, you must capture the return value, like so:

    myObj = SetFilterPosition( myObj, 7 );
    

    For more on handle and value classes, see the doc

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

Sidebar

Related Questions

I am really struggling to understand why, when I change my code to use
I'm struggling to understand what precisely does it mean when a value has type
I'm struggling to understand the documentation of sun.misc.Unsafe -- I guess as it's not
This is my first time programming and I'm struggling to understand what should be
I am struggling to understand what are nondeterministic polynomial-time problems and NP-complete problems. I
I'm struggling to understand how to combine the TimePicker http://trentrichardson.com/examples/timepicker/ solution to my existing
I'm really struggling to understand cocos2d 2.0 and how its layers and coordinates work.
I'm struggling to understand how to be able to clone a git repository from
I'm struggling to understand the advantage of using the orange circle view controller in
Hi guys I was looking at this code but I'm struggling to understand what

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.