function ThCond alloy = input('Enter the type of metal alloy:', 's'); T = input('Enter temperature(K) to calculate thermal conductivity:','s'); switch alloy case 'Al2' if (298 <= T) && (T <= 840) k = 149.7+0.0809*T-(1*10^(-4))*(T^2); fprintf('\nThe thermal conductivity(k_s) is $%6.2f\n', k') elseif (298 <= T) && (T <= 773) k = 76.64 + 0.2633*T - (2*10^(-4))*(T^2); fprintf('\nThe thermal conductivity(k_s) is $%6.2f\n', k') else disp('Invalid Temperature Input!'); end end end
MATLAB: Am I getting this error “Operands to the || and && operators must be convertible to logical scalar values.”
operands error
Related Question
- My function will not work to calculate the ‘Cumene inlet temperature’ section
- Using an if/else statement inside of a for loop
- Undefined function ‘times’ for input arguments of type ‘cell’.
- I am getting an error in the code stating that,”Operands in the operator || and && must be convertible to scalar”. I am very new to programming so can’t really find out where the mistake is
Best Answer
Delete the 's' from the temperature input. You want a number, not a string.
Then it works.