필터 지우기
필터 지우기

function without matching end

조회 수: 56 (최근 30일)
Ricky
Ricky 2013년 7월 4일
hello everyone,
I have got a m file which reads in data and plots the data in a GUI. In the main file itself there are many functions written. My understanding was that each function needs an end statement. In the code that I have functions are without end statement. What could be the reason for this . I am copying part of code for reference.
function panel_sp_1_CreateFcn(hObject, eventdata, handles)
set(hObject, 'UserData', 0);
The above function is from my code. The function does not have an end statement.

채택된 답변

Jan
Jan 2013년 7월 4일
The trailing "end" is a new feature in Matlab, which is required for nested functions. The old style without a trailing "end" will be kept for backward compatibility without any drawbacks. But when the programmer decides to use the new nested functions or the new style for one of the functions stored in an M-file, all functions must be closed by an "end" to keep the integrity.

추가 답변 (1개)

Matt J
Matt J 2013년 7월 4일
편집: Matt J 2013년 7월 4일
No, sub-functions do not necessarily have to have end statements. However, once you close one sub-function with an end statement, you must do so for all functions within that mfile.
  댓글 수: 1
Matt J
Matt J 2013년 7월 4일
편집: Matt J 2013년 7월 4일
Also, nested functions must be closed with "end" and if a nested function is used anywhere inside your mfile, all sub-functions will then require an "end" statement.
Functions in classdef files must also be enclosed in end statements.

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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by