如何在MATLAB中显示图表中的矩阵?

问题描述 投票:-1回答:1

如何在图表中显示矩阵?我可以使用Python在Python中执行此操作:

import numpy as np
import matplotlib.pyplot as plt
def plot_filter(filters,tex):
    fig, ax = plt.subplots()

    for i in range(filters.shape[0]):
        for j in range(filters.shape[1]):
            c = hori[i][j]
            ax.text(i+0.5, j+0.5, str(c), va='center', ha='center')

    ax.set_xlim(min_val, filters.shape[0])
    ax.set_ylim(min_val, filters.shape[1])
    ax.set_xticks(np.arange(filters.shape[0]))
    ax.set_yticks(np.arange(filters.shape[1]))
    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.grid()

    plt.title(tex)

hori = np.array([[0, 0, 0], [1, 2, 1], [0, 0, 0]])
plot_filter(hori, 'Horizontal')

如何在MATLAB中做到这一点?

结果应如下所示:

result_matrix

matlab matrix matlab-figure
1个回答
1
投票

你可以使用cellplot来达到这个目的。

h = cellplot({0 1 0; 0 2 0; 0 1 0});
title('Horizontal');

这使:

img1

并删除红色框,使用:

set(h(2:2:end),'EdgeColor', [1 1 1], 'FaceColor', [1 1 1]);

img2

© www.soinside.com 2019 - 2024. All rights reserved.