Asking for user input of numbers and letters.

26 次查看(过去 30 天)
Hi, I coded a program that can can take an image of a lisence palte and output it's numbers and letters. Now I'm trying to set up a way for the user to enter the correct lettes/numbers of the lisence plate to see if it matches with the letters and numbers generated by MatLab I'm just not sure how. I'm not sure how the user can input a line of both numbers and letters as input. For reference noPlate is the name of the numberplate generated by matlab.
x = input('What is the correct value of the lisence plate? ')
if (x==noPlate)
output('Nice')
else
output('The entered value does not match MatLab. Would you like to try again? (Y/N)')
end
Thanks, any help will be appreciated!
  1 个评论
David Hill
David Hill 2022-3-3
Is noPlate a character array (exampple 'F4RE9')? If not it would be easier to convert noPlate to a character array.
if isequal(x,noPlate) %should use isequal
You could convert 'F4RE9' to both letters and numbers in a cell array
x= 'F4RE9';
a=mat2cell(x',ones(size(x')));
for k=1:length(a)
if a{k}>='0'&&a{k}<='9'
a{k}=str2double(a{k});
end
end
%now a is a cell array of letters and numbers and isequal will still work
%as long as noPlate is in same cell array

请先登录,再进行评论。

回答(1 个)

Abolfazl Chaman Motlagh
if the plate (variable) could have both number and latters, deal with them like string. for getting input as string you need extra option 's' . for comparing two string use strcmp.
User_input = input('What is the correct value of the lisence plate? ','s');
if strcmp(User_input,noPlate)
output('Nice')
else
output('The entered value does not match MatLab. Would you like to try again? (Y/N)')
end
noPlate should be string too. like:
noPlate = '123J45';

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by