0

I have a matrix full of zeros. I would then like to change one 0 at a time to the value one. It has to be me deciding which element I would like to change. I have tried the following:

    classdef project < handle

properties
      scheme
end

methods
    function obj = project(antpro,antmed)
        obj.scheme = zeros(antpro,antmed);         
    end      

    function obj = AddEmployee(pronav,mednav)
        % Function adding a employee to the scheme
        obj.scheme(pronav,mednav) = 1;
    end
 end 

end

I hope it is somewhat clear what I want to do. When I run this code i get the message: "Undefined function 'AddEmployee' for input arguments of type 'double'."

I really do not understand this, as all my files are located in the same folder, and that it is the path for my matlab session.

Thank you in advance /Lasse

2 Answers 2

1

The declaration of methods in matlab requires passing obj as a first argument. Below is a link for the corresponding matlab documentation: http://www.mathworks.nl/help/matlab/matlab_oop/ordinary-methods.html#brdqipw-1

Sign up to request clarification or add additional context in comments.

4 Comments

This made little sense? Are you saying that my first method, need to be function obj = project(antpro,antmed) obj = zeros(antpro,antmed); end instead?
I would try this declaration:function AddEmployee(obj,pronav,mednav) The first method seems ok
This has solved my problem! Thank you very much, thought I had tried that already, but apparently not. It seems in the documentation that you can use both? Maybe I had misinterpreted!?
My matlab seems inconsistent in what it accepts.. Nice when you are programming.. I try something and it works, and creates something just like it for other values, and then stops working.. well well..
0

This is a class and you need to create an instance of it and call its AddEmployee method (although I'm not sure how you managed to create it without knowing this).

>> prj = project(); % Create an instance
>> prj.AddEmployee('a', 'name'); % Call a method in the instance

Sounds like you will probably find the this information of use. See also the Object Oriented Programming documentation.

3 Comments

I just thought that I created the instance as I created the matrix with zeros. All I thought I needed was a function to change the values in the already exiting matrix, but that might apprently not be a possibility..
It sounds like you want the method to live outside the scope of this isntantiation. Can you make the function static?
I am sorry to report, that i do not know what that means, and sorry to say that I must be the most hopeless case in this forum, so please accept my foolishness..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.