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!