Understanding how to apply for loop ?
Afficher commentaires plus anciens
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 commentaires
assigning your function to "s^t" does not work as that's not a valid variable name. calling it just "s" works:
snr1=2;
snr2=3;
I=1;
for t=1:3
s = [snr1^(t-1), snr2^(t-2), I^(t-1)]
end
chaaru datta
le 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
chaaru datta
le 4 Nov 2022
Modifié(e) : chaaru datta
le 4 Nov 2022
Réponses (1)
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'})
1 commentaire
VBBV
le 5 Nov 2022
you can use table function
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
