Why Function Keyword is invalid here in line 14
Show older comments
%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
dpb
on 26 Jul 2017
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.
Jan
on 26 Jul 2017
@MD SAIF ALI: Please post the complete error message.
Answers (1)
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
MD SAIF ALI
on 28 Jul 2017
dpb
on 28 Jul 2017
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.
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!