Clear Filters
Clear Filters

Understanding how to apply for loop ?

2 views (last 30 days)
chaaru datta
chaaru datta on 4 Nov 2022
Commented: VBBV on 5 Nov 2022
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 Comments
Daniel Neubauer
Daniel Neubauer on 4 Nov 2022
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 on 4 Nov 2022
Edited: chaaru datta on 4 Nov 2022
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).

Sign in to comment.

Answers (1)

VBBV
VBBV on 5 Nov 2022
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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!