Borrar filtros
Borrar filtros

Undefined Function ,,,,, for input arguments of type 'char'

9 visualizaciones (últimos 30 días)
Lewis Samuels
Lewis Samuels el 15 de En. de 2017
Comentada: Lewis Samuels el 30 de En. de 2017
Thank you in advanced. Just creating a function for a student number checker. 'Yes this is an assignment'. I would very much appreciate any help. If the error is easy to spot please just give me a hint ahha. This is my function:
%Question 3, Student Number Success Function
function [ LoginSuccessful ] = ValidSN( Studentnumber )
% ValidSN is a function that asks for the user's Student Number
% and confirms that their input is valid within Griffith College
% The function will return "Login Successful" if the first input
% start's with a 's' or 'S' and is 8 inputs long is size
% and only number after the 's', 'S'.
% Function[LoginSuccessful/UnSuccessful] = ValidSN(studentnumber)
% Step 1, Check the length.
StudentNumberLength = size(Studentnumber);
if StudentNumberLength~=8;
disp('Your student number length is incorrent, it must be 8 charaecters long');
LoginSuccessful = 0;
end;
% Step 2, Check the input starts with an 's' or 'S'.
S_or_s = Studentnumber(1);
if S_or_s~= 's' && S_or_s~= 'S'
disp('First input must start with an ''s'' or an ''S''');
LoginSuccessful = 0;
end
% Step 3, Check input 2-to-8 are numerical inputs only.
for SNLength = 2:8
if Studentnumber(SNLength)~= 2:8
disp('Not a numerical input.')
LoginSuccessful = 0
else
disp('Login Successful');
url = 'https://www.mathsworks.com'
web = 'www.mathsworks.com'
LoginSuccessful = 1;
end
end
And I'm calling it from this script.
%%QUestion 3
% SNumber checker
% This script calls on the function "isValidStudentNumber"
clc
clear all
% Student Number Checker called to the function ValidSN
% Step 1, Requires Input
while 1
s = input('Student Number: ', 's');
[Login] = ValidSN(s);
disp(Login)
url 'https://www.mathsworks.com'
web = 'www.mathsworks.com'
end
  1 comentario
Jan
Jan el 15 de En. de 2017
I've edited the code using the "{} Code" button to make it readable. Please do this by your own in the future - thanks.

Iniciar sesión para comentar.

Respuesta aceptada

Niels
Niels el 15 de En. de 2017
Editada: Niels el 15 de En. de 2017
i run your code, and i did not get any error message
s = input('Student Number: ', 's');
[Login] = ValidSN(s);
disp(Login)
Student Number: s12873654
Your student number length is incorrent, it must be 8 charaecters long
Not a numerical input.
Not a numerical input.
Not a numerical input.
Not a numerical input.
Not a numerical input.
Not a numerical input.
Not a numerical input.
0
your problem is that your "check" if the input is a number is wrong
if Studentnumber(SNLength)~= 2:8 ???
first of all studentNumber is a string so Studentnumber(2) and so on are all string. So if you want to check if 2:8 are numerical inputs use str2num and check if its true
if isempty(str2num(Studentnumber(SNLength))) % is empty if argument is no number
  2 comentarios
Walter Roberson
Walter Roberson el 15 de En. de 2017
To test for '0' to '9' you can use isdigit(). To test against a restricted set of digits such as '2' to '8' you could either do a pair of tests,
if var>= '2' && var <= '8'
Or you can use
ismember(var, '2':'8')
Lewis Samuels
Lewis Samuels el 30 de En. de 2017
Thank you. I used this in another code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by