0

I am trying to create a simple method within a handle class that can assign two values to a cell array. The first value is a number, just a observation number. The next value has to be two letter string. I have tried the following:

function addemp(obj, num,ini)
        obj.empnam(num,:) = {num,ini};
    end

Where, mednum is the observation number, and medini is the string. I have tried calling the function like this:

Addemp(m,1,'ES')

Where m is the object that holdes the empty empnam class property.

This returns the error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

So i hope my idea is pretty clear, and I do believe that it is a simple syntax error.

Thank you very much in advance

/Lasse

4
  • how do you define / init property obj.empnam? Commented Apr 30, 2013 at 15:54
  • It is just empty? I am loading it by a constructor function: m = scheme Which just gives me the four empty properties that I have decided to have. Commented Apr 30, 2013 at 15:58
  • My code does seem to run as the array is already created, but how do I create an empty cellarray? Just cell()? As this might be the solution to my own problem.. Commented Apr 30, 2013 at 16:18
  • It seems to have been solved, but maybe not with the most beautiful solution. This is what I did: function addemp(obj, num,ini) if isa(obj.empnam, 'cell') == 0 obj.empnam = {}; obj.empnam(num,1:2) = {num,ini}; else obj.empnam(num,1:2) = {num,ini}; end end This seems to have done it. The problem as I see it, was the fact that the property was empty and did not now how to act. Not adding this logical creates an empty cell array if there is not one already. Thanks for the inputs! /Lasse Commented Apr 30, 2013 at 16:51

2 Answers 2

1

It seems to have been solved, but maybe not with the most beautiful solution. This is what I did:

function addemp(obj, num,ini)
        if isa(obj.empnam, 'cell') == 0
            obj.empnam = {};
            obj.empnam(num,1:2) = {num,ini};
        else
            obj.empnam(num,1:2) = {num,ini};
        end
end

This seems to have done it. The problem as I see it, was the fact that the property was empty and did not know how to act. It does with matrices but not with cell arrays. Adding this logical creates an empty cell array if there is not one already.

Thanks for the inputs! /Lasse

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

Comments

0

This error message indicates that you are trying to store an array like variable to a scalar location. Have you tried this:

function addemp(obj, num,ini)
        obj.empnam(num,:) = {{num,ini}};
end

or first thing formost

function addemp(obj, num,ini)
        disp(size(obj.empnam(num,:)));
end

1 Comment

The first idea seems to create a new problem, giving me the message: Conversion to double from cell is not possible. I have tried a lot of different things during the day, and this is one of the messages I have seen a lot, just can't seem to figure out how to fix it :)

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.