for loop in matlab

1 visualización (últimos 30 días)
grace lim
grace lim el 31 de Mzo. de 2022
Respondida: Santosh Fatale el 7 de Abr. de 2022
syms Av Riopamp Riminus Rf Ro omega Ciminus
h11=Riopamp+((Riminus*Rf)/(Riminus+Rf))
h12=Riminus/((Riminus+Rf))
h21=-(((Av*Riopamp)/Ro)+(Riminus/Rf))
h22=(Ro+Riminus+Rf)/((Ro*(Riminus+Rf)))
h11new=subs(h11,Riminus,Riminus-(1/(1i*omega*Ciminus)))
simplify(h11new)
how to repeat this code(bottom) for all h12 h21 h22?
h11new=subs(h11,Riminus,Riminus-(1/(1i*omega*Ciminus)))

Respuestas (1)

Santosh Fatale
Santosh Fatale el 7 de Abr. de 2022
Hi Grace,
I understand that you have four symbolic variables h11, h12, h21, h22. You expressed the respective expression for each of these variables using other symbolic variables. You want to substitute new value for one of the symbolic variable which is a part of the expression and evaluate expression of variables h11, h12, h21, and h22 for this new value. I would like to suggest you to use struct datatype as follows to ease tasks which you want to achieve.
syms Av Riopamp Riminus Rf Ro omega Ciminus
T = struct;
T.h11=Riopamp+((Riminus*Rf)/(Riminus+Rf))
T.h12=Riminus/((Riminus+Rf))
T.h21=-(((Av*Riopamp)/Ro)+(Riminus/Rf))
T.h22=(Ro+Riminus+Rf)/((Ro*(Riminus+Rf)))
h11new=subs(T,Riminus,Riminus-(1/(1i*omega*Ciminus)))
for iterVar1 = 1 :2
for iterVar2 = 1: 2
simplify(h11new.("h"+iterVar1+iterVar2))
end
end
The individual fields of the structure, which are variables in your case, can be accessed by dot notation as follows:
>> T.h11
For more info on struct datatype, please check out the documentation link.

Categorías

Más información sobre Numbers and Precision en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by