Why Function Keyword is invalid here in line 14

%Call back Function
function callbackfn(source,evendata)
set([hsttext huitext],'Visible','off');
%Get the string that the user entered and print
%it in big red letters
printstr = get(huitext,'String');
hstr= uicontrol('Style','text','BackgroundColor','White','Postion',[100,400,400,55],'String',printstr,'ForegroundColor','Red','Fontsize',30);
set(hstr,'Visible','on');
end
end

2 Comments

Well we can't tell as there aren't 14 lines but that there's another end statement implies this is inside another code block of somesort...need the rest of the context and post the entire error message and the code that generated it; don't parse stuff out.
@MD SAIF ALI: Please post the complete error message.

Sign in to comment.

Answers (1)

Jan
Jan on 26 Jul 2017
Edited: Jan on 26 Jul 2017
Function definitions are allowed in function files, as nested functions in modern Matlab versions, and inside scripts since 2017a. Therefore the context (which you did not post) is important and the Matlab version you are using.
Try an automatic indentation to identify the level of nesting: Ctrl-a Ctrl-i. What do you observe?

2 Comments

I m using MATLAB 2010
Then as Jan notes you're not allowed to define functions inside script files. Read the documentation discussion sections under 'Programming Fundamentals' for discussion of basic program structure and limitations.

Sign in to comment.

Asked:

on 26 Jul 2017

Commented:

dpb
on 28 Jul 2017

Community Treasure Hunt

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

Start Hunting!