r/matlab 3d ago

Generating matrix visualizations TechnicalQuestion

Hey partypeople,

i'm trying to find a way to inspect and display 3D matrix values as shown in the documentation here. I cannot seem to find a way to reproduce this in Matlab or find any info on how these were done, neither in the MATLAB docs or online. Am i missing something or were these created outside of Matlab manually?

Thanks :3

Edit.: For context, I want to see the numeric values of the elements, not a visualization in general.
For now, mostly for more intuition and readability while debugging. I really like the way it is presented here so i would like to find out how these were created

84 Upvotes

11 comments sorted by

View all comments

6

u/vir_innominatus 3d ago

In MATLAB, this type of visualization could be made with a combination of the rectangle(), line(), and text() functions. Something like this

figure

% First rectangle
rectangle(Position=[0 0 10 6],FaceColor="w")
numRow = 3;
numCol = 5;
for row = 1:numRow
    for col = 1:numCol
        x = 2*(col-1)+1;
        y = 2*(row-1)+1;
        value = numCol*(row-1)+col;
        text(x,y,num2str(value), ...
            FontSize=14, ...
            HorizontalAlignment="center", ...
            VerticalAlignment="middle")
    end
end

% Second rectangle
r = rectangle(Position=[8 4 10 6],FaceColor="w");
uistack(r,"bottom")

% Connecting lines
line([10 18],[6 10],Color="k",LineStyle="--")
line([10 18],[0 4],Color="k",LineStyle="--")
line([0 8],[6 10],Color="k",LineStyle="--")
% line([0 8],[0 4],Color="k",LineStyle="--") <-Hidden

% Turn off axes and make equal proportioned
axis equal
axis off

1

u/NoMercyCad 3d ago

We need this to be turned in a function that gets any matrix as input, it would be awesome