Understanding how to apply for loop ?
1 次查看(过去 30 天)
显示 更早的评论
Hello all, I am new to MATLAB and hence finding difficulty in understanding how should I apply for loop in the following case:
for t = 1,2,3.....
s^t = [snr1^(t-1), snr2^(t-1), I^(t-1)]
end
where snr1, snr2 and I are some variables.
I am getting confused due to presence of t-1.
Any help in this regard will be highly appreciated.
4 个评论
Daniel Neubauer
2022-11-4
well that cannot work because how do you want to adress t-1 if there was no previous instance in the first loop?
if you start later it'd work somehow like this:
snr1=2;
snr2=3;
I=1;
n=5;
t=[1:n]
for i=3:5
s = [snr1^(t(i-1)), snr2^(t(i-2)), I^(t(i-1))]
end
回答(1 个)
VBBV
2022-11-5
SNR1 = rand(1,100).'; % the vector with SNR1 values
SNR3 = rand(1,100).';% the vector with SNR3 values
I = randi([1 100],[1 100]).'; % the integer vector with I values within (1-100)
for t = 2:length(SNR1)
s(t,:) = [SNR1(t-1); SNR3(t-1); I(t-1)].';
end
T = table(s(:,1),s(:,2),s(:,3),'VariableNames',{'SNR1','SNR3','I'})
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!