0
私は信号を作成し、最初に作成したCT信号をサンプリングして離散時間信号を作成しようとしています。最後のfor-loopまではうまくいきますが、Tで分離されたN個のサンプルを取る必要があります。if文がなければ、インデックス外のエラーが出ています。信号の持続時間内にサンプリングを制限しなければなりませんでした。何らかの理由で、私のコードはif文に1回以上入りますが、デバッグではifとifの両方の値を出力しています。論理演算は複数の反復で真でなければなりませんが(印刷ステートメントは値を表示します)、ifステートメント内のステートメントは出力されません。ここで何が間違っていますか?MATLABのfor-loopにif文をネストするための特別な規則はありますか?
function x = myA2D(b,w,p,T,N)
%MYA2D description: Takes in parameters to construct the CT-sampled DT signal
%b,w,p are Mx1 vectors and it returns Nx1 vector.
timeSpace = 0:0.001:3*pi;
xConstT = zeros(size(timeSpace));
%Construct Xc(t) signal
for k = 1:size(b,1)
temp = b(k) .* cos(w(k).*timeSpace + p(k));
xConstT = xConstT + temp;
end
plot(xConstT);
%Sampling CT-Signal to build DT-signal
disp(strcat('xConstT size',int2str(size(xConstT))));**strong text**
x = zeros(N,1);
sizeConstT = size(xConstT);
for i = 0:N-1
index = i .* T .* 1000 + 1;
disp(strcat('indexoo=',int2str(index)));
disp(strcat('xConstSizeeee',int2str(sizeConstT)));
if index <= sizeConstT
disp(strcat('idx=',int2str(index)));
disp(strcat('xSize',int2str(sizeConstT)));
%x(i+1,1) = xConstT(index);
end
end
end