필터 지우기
필터 지우기

Understanding how to apply for loop ?

조회 수: 2 (최근 30일)
chaaru datta
chaaru datta 2022년 11월 4일
댓글: VBBV 2022년 11월 5일
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
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]
t = 1×5
1 2 3 4 5
for i=3:5
s = [snr1^(t(i-1)), snr2^(t(i-2)), I^(t(i-1))]
end
s = 1×3
4 3 1
s = 1×3
8 9 1
s = 1×3
16 27 1
chaaru datta
chaaru datta 2022년 11월 4일
편집: chaaru datta 2022년 11월 4일
This is the part which I am trying to code.
Also "s" at time instant "t" depends on SNR1 at time instant (t-1), SNR3 at time instant (t-1), and I at time instant (t-1).

댓글을 달려면 로그인하십시오.

답변 (1개)

VBBV
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'})
T = 100×3 table
SNR1 SNR3 I ________ _______ __ 0 0 0 0.5286 0.55894 61 0.32919 0.89355 43 0.86775 0.43205 21 0.55857 0.25263 25 0.75068 0.78974 84 0.87684 0.35155 93 0.96913 0.97962 73 0.046261 0.81734 99 0.88748 0.59252 96 0.97548 0.30953 13 0.063743 0.37548 45 0.49473 0.4175 84 0.15575 0.89957 75 0.84632 0.63998 31 0.68992 0.57802 14
  댓글 수: 1
VBBV
VBBV 2022년 11월 5일
you can use table function

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by