How can i run my integer number from this question ?

The question is :
Enter a character. If it is an uppercase letter, it outputs its
successor. If it is a lowercase letter, it outputs its leading character.
If it is another character, it will be output as it is.
Point to be noted , i want to execute the integer number with matlab function such as int8 , int16 like this . I'm going to share my code which i made. Can anyone help me to find the problem ?
Thanks in advance
My created code is :
inputLetter = input('Please input a string number : ','s');
if(inputLetter == upper(inputLetter))
fprintf( 'Its a successor!');
elseif (inputLetter == lower(inputLetter))
fprintf( 'Its a leading charecter!');
elseif(inputLetter == int16(inputLetter))
fprintf('Its is obvoiusly '+inputLetter);
else
fprintf('Incorrect input ! ');
end

7 Comments

>> inp = 'Xx!';
>> out = char(inp-(lower(inp)==inp)+(upper(inp)==inp))
out = Yw!
@Stephen Cobeldick Where i need to write this line ?
Can you please write full code step by step ? Thanks for your attention.
There is no point in int8 or int16 in that code. You only have three cases: uppercase, lowercase, and anything else. Once you have tested for uppercase and lowercase, then you know you must have something else.
@Walter Roberson Then Why i didn't get anything else. If i input 1 then my output come 'It's a Successor!'. But i want 1 as a output . What i make mistake ? Thanks for your attention sir.
What is the expected value of upper('1') ?
If i didn't input string element then my output will be come as it is . So do you mean my input has problem ? I don't want to take 1 as a string . You can see my question :
" Enter a character.
If it is an uppercase letter, it outputs its successor.
If it is a lowercase letter, it outputs its leading character.
If it is another character, it will be output as it is."
According to this question what i make mistake sir ?
You tested whether the input is an uppercase character by testing
if inputLetter == upper(inputLetter)
But when you take upper() of something that is not a letter, then the result is the same as the input -- upper('1') is the same as '1' .
I recommend you see isstrprop() if you want to get as far as supporting uppercase and lowercase Unicode characters.
If you only want to bother handling English, then I suggest you use ismember()

Sign in to comment.

Answers (1)

You can convert the strinng to a double number then apply int8 or int16:
int16(str2double(inputLetter))

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!