简体   繁体   中英

How can I plot a gridded figure as shown in Matlab?

在此处输入图片说明

I would to plot above the above figure with some or none characters in the boxes. Thanks.

If you really want a plot, you can do it with a function like this:

function plotGrid(x)

dims = size(x);

% Get grid
tick_x = linspace(0, 1, dims(2)+1);
tick_y = linspace(0, 1, dims(1)+1);

% Get center points
pt_x = (0.5:dims(2)) / dims(2);
pt_y = (0.5:dims(1)) / dims(1);

[pt_x pt_y] = meshgrid(pt_x, pt_y);

% Plot
figure; hold on; axis off
plot([tick_x; tick_x], repmat((0:1)', 1, dims(2)+1), 'k')
plot(repmat((0:1)', 1, dims(1)+1), [tick_y; tick_y], 'k')
text(pt_x(:), pt_y(:), x(:), 'HorizontalAlignment', 'center')

For example:

>> x = num2cell(randi(10, [10 6]));
>> plotGrid(x)

在此处输入图片说明

One method for displaying tabular data on a figure is to use UITABLE :

data = 

    'U1'    'U2'    'U3'    'U4'    'U5' 
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []       []
      []      []      []      []    'U85'

>> uitable('Data', data, 'Units', 'normalized', 'Position', [0 0 1 1]);

which produces:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM