Im trying to create a button that prompts user to select file to load and display.
function loadbutton_Callback(hObject, eventdata, handles)
[datafile datadir] = uigetfile('*.csv');
end
When I run this code on a separate file it works but when I added to my code it gives this error
*Function definitions are not permitted in this context.*

 채택된 답변

Adam
Adam 2017년 3월 22일
편집: Adam 2017년 3월 22일

0 개 추천

What version of Matlab are you using?
I'm guessing you are not in the latest and your main file is a script which does not allow subfunctions.
Just change your script into a function by adding
function myMFilename( )
at the top, obviously replacing myMFilename with whatever is the name of your file.
or move this function into a file of its own somewhere on your path.

추가 답변 (1개)

Yasaman Best
Yasaman Best 2017년 3월 22일

0 개 추천

R2016a . It works if I run it in a separate file but shows error when I add it to my file! So odd

댓글 수: 1

Adam
Adam 2017년 3월 22일
It isn't odd, it is for the reason I explained in my answer. Subfunction definitions are not allowed in a script. Apparently they are in the lastest version of Matlab, but I've never tried them. I try to avoid scripts as much as possible!

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

카테고리

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

태그

질문:

2017년 3월 22일

댓글:

2017년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by