# Asking for user input of numbers and letters.

18 visualizaciones (últimos 30 días)
Thomas Robertson el 3 de Mzo. de 2022
Comentada: David Hill el 3 de Mzo. de 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 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
David Hill el 3 de Mzo. de 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

Iniciar sesión para comentar.

### Respuestas (1)

Abolfazl Chaman Motlagh el 3 de Mzo. de 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';
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by