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

9 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-1-15
I've edited the code using the "{} Code" button to make it readable. Please do this by your own in the future - thanks.

请先登录,再进行评论。

采纳的回答

Niels
Niels 2017-1-15
编辑:Niels 2017-1-15
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 个评论
Walter Roberson
Walter Roberson 2017-1-15
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')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by