Understanding how to apply for loop ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Daniel Neubauer
am 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]
for i=3:5
s = [snr1^(t(i-1)), snr2^(t(i-2)), I^(t(i-1))]
end
Antworten (1)
VBBV
am 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'})
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!