如何使用matlab创建一个asterik矩形

Ehm*_*hal 1 matlab

我是matlab的初学者.任何人都可以告诉如何在图像中创建一个asterik矩形:

在此输入图像描述

Lui*_*ndo 6

这是一种没有循环的方法:

m = 5;     %// number of rows
n = 12;    %// number of cols
c = ' ';   %// inner character
C = '*';   %// outer character
x = repmat(c, m, n);   %// create m x n array of c
x([1 end], :) = C;     %// replace top and bottom with C
x(:, [1 end]) = C;     %// replace left and right with C
Run Code Online (Sandbox Code Playgroud)

这给了

>> disp(x)
************
*          *
*          *
*          *
************
Run Code Online (Sandbox Code Playgroud)