make code more rigorous
2 ビュー (過去 30 日間)
古いコメントを表示
I have two seperate functions, fR1 AND fR2 however i would like to combine it into one function as i have to seperature function files.
currently i have this code to calculate rho1 and rho2
Any idea on how to combine it and make it more efficient
clear;clc
L = 20
A = 230
dT =[100:1:120]
a = 0.0039
rho1 = 0.0178
rho2 = 0.0170
a2 = 4.3e-3
b2 = 0.6e-6
rho = rho1*(1+a*dT)
rhoo = rho2*(1+a*dT+b2*(dT).^2)
R1 = fR1(rho,L,A)
R2 = fR2(rhoo,L,A)
hold on
plot(dT,R1)
plot(dT,R2)
xlabel('Temperature')
ylabel('Resistivity')
legend('')
the 2 function filed i have are essential the same thing:
fR1
function R = fR1(rho,L,A)
R = rho*L/A
end
fR2
function R = fR2(rhoo,L,A)
R = rhoo*L/A
end
0 件のコメント
回答 (1 件)
David Hill
2022 年 2 月 10 日
Why have functions if you only call them once?
L = 20
A = 230
dT =[100:1:120]
a = 0.0039
rho1 = 0.0178
rho2 = 0.0170
a2 = 4.3e-3
b2 = 0.6e-6
rho = rho1*(1+a*dT)
rhoo = rho2*(1+a*dT+b2*(dT).^2)
R1 = rho*L/A;
R2 = rhoo*L/A;
hold on
plot(dT,R1)
plot(dT,R2)
xlabel('Temperature')
ylabel('Resistivity')
legend('')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!