How to use "for" function for looping with 3 variables

4 vues (au cours des 30 derniers jours)
Ericka Huang
Ericka Huang le 4 Avr 2020
Commenté : Ericka Huang le 6 Avr 2020
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

Réponse acceptée

David Hill
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;
  1 commentaire
Ericka Huang
Ericka Huang le 6 Avr 2020
thank you very much for your help.... I can use this for my script

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by