How to output matrix dimensions together with its content?

后端 未结 5 826
醉话见心
醉话见心 2021-01-02 02:05

Is it possible to make GNU Octave to output matrix dimensions together with its content? For example, it should produce smth. like this:

octave:1> X = [1          


        
5条回答
  •  太阳男子
    2021-01-02 02:49

    In MATLAB, create display.m in a folder called @double somewhere in your path with this content:

    function display(v)
    name = inputname(1);
    if isempty(name)
        name = 'ans';
    end
    s = num2cell(size(v));
    fprintf('\n%s [%d%s] =\n\n', name, s{1}, sprintf('x%d', s{2:end}));
    builtin('disp', v);
    end
    

    This way you override the display method for class double, and get exactly what you have described. However, this will not work for other classes like int8, logical or cell. You have to override the method for all classes you are interested in. Example:

    >> A=ones(2,2,2)
    
    A [2x2x2] =
    
    (:,:,1) =
         1     1
         1     1
    (:,:,2) =
         1     1
         1     1
    

提交回复
热议问题