Asking for user input of numbers and letters.

23 Ansichten (letzte 30 Tage)
Thomas Robertson
Thomas Robertson am 3 Mär. 2022
Kommentiert: David Hill am 3 Mär. 2022
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 Kommentar
David Hill
David Hill am 3 Mär. 2022
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh am 3 Mär. 2022
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';

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by