How do write a function within the same main code

조회 수: 15 (최근 30일)
Watheq Elias
Watheq Elias 2011년 4월 8일
Hello everybody,
I want to know if it is possible to write a function within the same main code rather than write it in separate M file.
Thanks in advance for any help.

채택된 답변

Matt Fig
Matt Fig 2011년 4월 8일
Put all of this into one M-file. Then call it like this: get_sub(5)
function [OUT] = get_sub(A)
OUT = subfun(A); % Call the subfunction.
function [OUT_SUB] = subfun(B)
OUT_SUB = B.^2;

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 4월 8일
yes with subfunctions

카테고리

Help CenterFile Exchange에서 Holidays / Seasons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by