Hi all,
I have written the following program to calculate the crosswind for a runway:
function [] = crosswind()fprintf('\n----- Crosswind -------------------------------------------------- \n');while 1 % Numerically Defining Input Responses
yes = 1; Yes = 1; yEs = 1; yeS = 1; YEs = 1; yES = 1; YeS = 1; YES = 1; y = 1; Y = 1; no = 2; No = 2; nO = 2; NO = 2; n = 2; N = 2; %fprintf('-------------------------------------------------------');
%fprintf('\nWelcome to the crosswind component calculator. \n')
%fprintf('This funciton is not a substitute for instructor input. \n');
%fprintf('Input directions in degrees, and velocity in knots. \n\n');
% Asking for Information
runwayDesignator = input('Two digit runway identifier: '); windDegrees = input('Direction wind is from in degrees: '); windMagnitude = input('Wind speed in knots: '); % Computing Information
runwayDegrees = runwayDesignator * 10; difference = abs( runwayDegrees - windDegrees ); multiplier = sind( difference ); crossWind = abs( windMagnitude * multiplier ); % Printing the Result
if crossWind >= 20 fprintf(2, '\nThere are %d knots of crosswind for runway %d. \n', crossWind, runwayDesignator) end if crossWind < 20 fprintf('\nThere are %d knots of crosswind for runway %d \n', crossWind, runwayDesignator) end % Asking for further responses / exiting
fprintf('\nWould you like to calculate the crosswind for another runway?\n'); answerA = input('Type response here: '); if answerA == 2 break; end endend
For example to run the funciton input the numbers:
12
360
20
The funciton works, but I would like the result to be printed in non scientific notation. To do this I tried to insert a like such as:
crossWindLong = sprintf('%2.2f', crossWind);
But when I input this, and run the funciton keeping the input vairables (12, 360 and 20) the same, the function returns some garbage result.
How would I avoid this?
Thanks
Best Answer