How do i link my menu bar function to my for loop. [Error indicates Not Enough Input argument]

function [Agelessthan25,Agebetween25to50,Ageabove50]= Agecategory(AgeofCasualty)
Agelessthan25=0;
Agebetween25to50=0;
Ageabove50=0;
for x=(1:length(AgeofCasualty));
curage = AgeofCasualty(x);
if curage < 25
Agelessthan25= Agelessthan25 + 1;
elseif curage >= 25 & curage < 50;
Agebetween25to50 =Agebetween25to50 +1;
else curage >= 50;
Ageabove50 = Ageabove50 +1;
end
end
fprintf('Agelessthan25 is %d\n', Agelessthan25)
fprintf('Agebetween25to50 is %d\n', Agebetween25to50)
fprintf('Ageabove50 is %d.0\n', Ageabove50)
end

댓글 수: 2

Do you want to link the above program to GUI Menu bar ? or where you want to call this function. ?
Hi Ganesh Hegade, Thanks for the response.
what i am trying to do is to run a menu function/bar for this script. Hence, if i were to click the option of "Agecategory" this program should run by itself. However, when i input the function into this, i can't seem to run this properly. But if i were to suppress the function keyword, my script runs.

댓글을 달려면 로그인하십시오.

 채택된 답변

Kenneth - please show the callback which includes the code that calls the Agecategory function. Given the error message and the signature of this function, I suspect that you are not passing the AgeofCasualty input parameter into this function. Since the signature is
function [Agelessthan25,Agebetween25to50,Ageabove50]= Agecategory(AgeofCasualty)
then you must call it like
[Agelessthan25,Agebetween25to50,Ageabove50]= Agecategory(42);
where 42 is passed as the input parameter into this function.

댓글 수: 3

switch choice
case 1
Overview_Explanation;
case 2
Agecategory
As Geoff Hayes guessed, you are not passing the input argument to your Agecategory function. It ought to be obvious that it needs this because the function makes no sense if you don't give it the one input it needs.
It is very important to learn the meaning of error messages. A colleague of mine used to always just see 'red text' on the screen and then flounder around for a while trying to work out what was wrong when reading the exact error message tells you, as in this case:
'Not Enough Input arguments'
That is the difference between a function and a script, a function takes input arguments, though if you converted it from a script you must have realised this in order to set it up with an input argument in the first place!
Hi Adam, Thanks for the reply
i do get where you're coming from, Once again, without the function keyword, i am able to run this script without any hassle. However, i am trying to link this script with respect to my menu option. This consist of a process where a "call function" has to be used to link the script together.
Then again,this function has to consist of my so called “Menu choice” as well as it has to link with my workspace variables. i do apologise if this is getting too repetitive as I am still a novice matlab programmer.
best wishes!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2016년 11월 23일

댓글:

2016년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by