0

Here is my code:

angles = 'Please enter the Euler angles in degrees- yaw(x),pitch(y) and roll(z) \n:';
ea = input(angles,'s');
cos(ea(1))

This code saves the elements of the input string 'ea' as char. How should I save the input in degrees directly? Using cos(ea(1)) gives an error:

Undefined function 'cos' for input arguments of type 'char'. 

2 Answers 2

1

Firstly the input function returns a string, so you will need to convert that to a numerical value. Secondly cos takes input in radians not degrees, so you will either need to convert to radians or to use cosd instead of cos.

angles = 'Please enter the Euler angles in degrees- yaw(x),pitch(y) and roll(z) \n:';
ea = str2double(input(angles,'s'));
cosd(ea(1))

You can also use input without the 's' parameter. In that case input will evaluate the expression passed as a string and return the result. For example in that case not only can you pass singles values such as '90' but you could also pass things like: 3*180/4 as input

angles = 'Please enter the Euler angles in degrees- yaw(x),pitch(y) and roll(z) \n:';
ea = input(angles);
cosd(ea(1))
Sign up to request clarification or add additional context in comments.

1 Comment

Nice example! As we all know x*180/4 is the formula for converting x from radians to degrees, for pi=4.
0

By doing input(prompt,'s'), you're specifically telling it to return the user input as string. You need to drop the 's' to get numeric input. Also, you need to do input three times to actually get three inputs. Use a structure to store the input in different fields because it can take string as a field name. It's more organized and easily understandable.

prompt = 'Please enter Euler angles in degress, ';
choice = {'yaw(x): ', 'pitch(y): ', 'roll(z): '};

for ii = 1 : numel(choice)
    ea.(choice{ii}(1:end-5)) = input([prompt, choice{ii}]);
end

But of course, this will also work :

for ii = 1 : numel(choice)
    ea(ii) = input([prompt, choice{ii}]);
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.