why do I receive two numbers when I use Find command?
Afficher commentaires plus anciens
could you please figure out the problem why do i get twi indecies for tg
which the first index t( 45633 ) is not giving the correct index but i still receive it.
clear
close all, clc
ca = 1014 ;
ci = 2050 ;
cw = 4218 ;
eps = 27.03 ;
LWC = 0.001 ;
Haw = 500 ;
His = 100 ;
ki = 2.18 ;
kw = 0.571 ;
Le = 13.4 ;
LF = 3.344 * 1e5 ;
LE = 2.26 * 1e6 ;
p0 = 6.3*1e4 ;
v = 90 ;
beta = 0.55 ;
rho_g = 917 ;
rho_r = 880 ;
rho_w = 1000 ;
X = 11 ;
r = 0.9 ;
R = 287.05 ;
Tf = 273.15 ;
cp = 1012 ;
Ta= 263.15;
Ts=Ta;
Qa=r*Haw*((v)^2/(2*cp));
Qk=LWC*beta*((v^3)/2);
sigma = 5.67*1e-8;
t=0:0.001:320;
for i=1:length(t)
Bg = (ki*(Tf-Ts)) / (LWC*beta*v*LF + (Qa+Qk)-((Haw+LWC*beta*v*cw+X*eps)*(Tf-Ta)));
tg = (rho_r /(LWC*beta*v))*Bg ; % time when first glaze appears
% B(i)=((Haw+X*eps+LWC*beta*v*cw-Qa-Qk)/(rho_g*LF))*t(i);
end
tg_index=find(abs(t-tg)<1e-3)
1 commentaire
Geoff Hayes
le 28 Déc 2021
@mehmet salihi - but both of those indices satisfy the condition that you are using in your call to find. For example,
>> abs(t(45633)-tg)
ans =
5.9622e-04
and
>> abs(t(45634)-tg)
ans =
4.0378e-04
where the ans to each is less than 1e-3.
Réponse acceptée
Plus de réponses (1)
Voss
le 28 Déc 2021
Evidently those two elements of t are within 0.001 of tg. If you want just the first element of t that is within 0.001 of tg you can say
tg_index=find(abs(t-tg)<1e-3,1);
but it seems more likely that you want the element of t that is closest to tg, in which case you can say
[~,tg_index]=min(abs(t-tg));
1 commentaire
mehmet salihi
le 28 Déc 2021
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
