MATLAB: How to find the number of times the data is in laminar, transition, and turbulent given the conditions

for loopif statement

R=[8902 29260 140589 12088 3906 70892 130791 59007 31802 2019];
k=0;
for x=1:length(R)
if R(x)<=2200
k=k+1;
f_laminar=(14)/(R(x));
fprintf('The number of times the data was in laminar is %4.3f.',k)
elseif (2200<R(x))&(R(x)<1000000)
k=k+1;
f_transition=(0.0891)/(R(x)^0.21);
fprintf('The number of times the data was in transition is %4.3f.',k)
elseif R(x)>=1000000
k=k+1;
f_turbulant=0.006;
fprintf('The number of times the data was in turbulant %4.3f.',k)
end
end

Best Answer

lam=nnz(R<=2200) ;
trans=nnz(2200<R & R<1000000 );
turb=nnz( R>=1000000 ) ;
fprintf('The number of times the data was in laminar is %4.3f.',lam)
fprintf('The number of times the data was in transition is %4.3f.', trans)
fprintf('The number of times the data was in turbulant %4.3f.', turb)