题目:
来源于Mathwork上的Cody,Problem 44245,Cell Operator *,
实现的过程比较简单,使用了repmat函数。函数构造如下,
function out_A = m_times(A, n)
%STAY HOME, STAY SAFE
%WEAR A MASK
if length(n)==1
N=[1,n];
else
N=n;
end
out_A=repmat(A,N);
end
测试如下,
m_times({2,3},2)
ans =
1×4 cell 数组
{[2]} {[3]} {[2]} {[3]}
m_times({2,3},[2 3])
ans =
2×6 cell 数组
{[2]} {[3]} {[2]} {[3]} {[2]} {[3]}
{[2]} {[3]} {[2]} {[3]} {[2]} {[3]}
m_times({[2,3] 8},3)
ans =
1×6 cell 数组
{1×2 double} {[8]} {1×2 double} {[8]} {1×2 double} {[8]}