Search code examples
matlabclassconstants

Colon operator on constant attribute in MATLAB class


I have a weird problem I can't solve and can't find any solution to on the internet:

classdef test
    properties(Constant)
        bla = {'Marker', 'o', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b'};
    end
end

Accessing test.bla with colon operator in command line WORKS: test.bla{:}. But it doesn't when I use it within another class:

classdef foo
    properties
    end
    
    methods
        function this = foo()
            test.bla
            
            a = test.bla;
            a{:}
            
            test.bla{:}            
        end
    end    
end

It's very cumbersome to use a = test.bla; a{:} all the time...


Solution

  • Indeed, it does not work! I was really surprised.

    I found out that you can use :

    x = {test.bla(:)};
    

    This will give you all of the elements.