for loop in matlab

1 回表示 (過去 30 日間)
grace lim
grace lim 2022 年 3 月 31 日
回答済み: Santosh Fatale 2022 年 4 月 7 日
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)))

回答 (1 件)

Santosh Fatale
Santosh Fatale 2022 年 4 月 7 日
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.

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by