x[t]是一个离散的时间周期性信号,在一个周期上定义如下
x[t] = {1 , 2 , 1 , 2 , 3 , 1 , 2 , 3 , 4.....}
我想在Matlab中以[0100]的间隔将其生成为周期性信号。但是,我无法为此编写代码。
在matlab中,如果你想生成周期性信号,有很多方法,其中之一是:
%x is array that represent discrete time signal.
%y is generated periodic signal
%n the number of periods
temp=x'*ones(1,n);
y=temp(:);
% where x' is transpose of x.
% if we suppose x=[1,2,3]
% if we want to repeat it five times we can say n = 5
% then temp will equal [ 1 1 1 1 1
% 2 2 2 2 2
% 3 3 3 3 3]
%fianlly y will equal [1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]
也许你可以像下面的一样尝试arrayfun
X = arrayfun(@(k) 1:k, 2:4, "UniformOutput",false);
x = repmat([X{:}],1,2);
它给出
x =
1 2 1 2 3 1 2 3 4 1 2 1 2 3 1 2 3 4