如何在图表中显示矩阵?我可以在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中执行此操作?
结果应如下所示: