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

14 ビュー (過去 30 日間)
Lewis Samuels
Lewis Samuels 2017 年 1 月 15 日
コメント済み: Lewis Samuels 2017 年 1 月 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')
Lewis Samuels
Lewis Samuels 2017 年 1 月 30 日
Thank you. I used this in another code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by