set class variables and set them in one function and call them in another funciton in matlab

To create class variables in MATLAB, you can define them inside the classdef block at the beginning of your class definition. Here's an example:

main.m
classdef MyClass
    properties
        myVariable1
        myVariable2
    end
    
    methods
        function setVariables(obj, var1, var2)
            obj.myVariable1 = var1;
            obj.myVariable2 = var2;
        end
        
        function useVariables(obj)
            disp(obj.myVariable1);
            disp(obj.myVariable2);
        end
    end
end
366 chars
19 lines

In this example, MyClass has two class variables: myVariable1 and myVariable2. These are defined in the properties block of the class definition.

The setVariables method takes in two arguments and sets the class variables myVariable1 and myVariable2 to those values. Note that we use the obj argument to access the class variables.

The useVariables method simply displays the values of myVariable1 and myVariable2.

Here's an example of using these methods:

main.m
myObject = MyClass();
myObject.setVariables('hello', 42);
myObject.useVariables();
83 chars
4 lines

This will output:

main.m
hello
    42
13 chars
3 lines

Here, we first create an instance of MyClass using the constructor (MyClass()). We then call the setVariables method on this object to set its class variables. Finally, we call the useVariables method to display the values of the class variables.

gistlibby LogSnag