How to use "for" function for looping with 3 variables
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I want to ask about how to use "for" function for calculating each iteration with 3 different variables. I want to calculate Wheston Bridge using different 3 variables. Here my code. Thank you
R1 = 100;
R2 = [200 : 1 : 300];
R3 = [250 : 1 : 350];
R4 = [300 : 1 : 400];
Vin = 10;
kk = 1;
for i = 1:length(R2)
for j = 1:length(R3)
for k = 1:length(R4)
Rs(kk) = (R2(i)./(R2(i)+R1))-(R4(k)./(R3(j)+R4(k)));
Vo(kk) = Vin*((R2(i)./(R2(i)+R1))-(R4(k)./(R3(j)+R4(k))));
kk = kk +1;
end
end
end
0 commentaires
Réponse acceptée
David Hill
le 4 Avr 2020
Modifié(e) : David Hill
le 4 Avr 2020
No need of for-loops:
[a,b,c]=meshgrid(R2,R3,R4);
Rs = a./(a+R1)-c./(b+c);
Vo = Vin*Rs;
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!