Skip to content
MathWorks - Mobile View
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 받기
MathWorks
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 받기
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃

비디오 및 웨비나

  • MathWorks
  • 비디오
  • 비디오 홈
  • 검색
  • 비디오 홈
  • 검색
  • 영업 담당 문의
  • 평가판 신청
3:22 Video length is 3:22.
  • Description
  • Full Transcript
  • Related Resources

Functions with Multiple Inputs or Outputs

From the series: Managing Code in MATLAB

Learn how to create MATLAB functions with multiple inputs and outputs.

Hello, this is Doug at the MathWorks bringing your video 248 about having multiple inputs and multiple outputs in a function. I'm going to start with a function that was already built that has one input and one output. And I'm going to convert this to support multiple inputs and multiple outputs. It really doesn't matter what the function does so much as that it is a function.

So I see here that, as soon as I go into this function, I set a variable number of terms for the Taylor series approximation. That's what we call hard coded. And maybe we want that to be a variable so that we can get more or less precision. So I'm going to change this to num terms, like this. And now we don't need to specify that right there.

And one test of this-- let's try this. And I'm going to go to the command window. Taylor sign of 0.5, and it says we didn't ask for enough terms. There we go. And let's say we want to have multiple outputs of this. Well, why don't we figure out what the error is? So I'm going to put some brackets around here, showing that we have multiple outputs coming.

And the way this is usually done is you put the most important output first. That way, if the user calls it and doesn't ask for both outputs, only the first one will be given. In this case, we usually want the approximation. But we might not always want the error. And so down here at the end-- let's make some room for it-- error is equal to sine of x minus the approximation.

So if we go back to the command window, we haven't asked for the second output. So it doesn't really change. However, if we say approx and error, like this, now we're getting them both and we can see what our error is in this little function. Something that people like to do in situations like this is put in some default values for number of terms. So if nargin, number of arguments in, equals one-- then we're going to say num terms is equal to some default value.

If we save that and go back to the command window, it doesn't change anything here. But if we don't give a second argument, it's still going to work. And of course, let's change the number of terms. And we can see the error gets much bigger or smaller as we change that. Thank you.

Related Products

  • MATLAB

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper
Related Information
Related Information
MATLAB Video Blog

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

This video will allow you to do input parsing so that you have the ability to overload functions, meaning allow them to react differently to different inputs.
4:05
Functions of Variable Numbers of Inputs and Outputs
View full series (10 Videos)

Related Videos:

4:05
Managing Code in MATLAB: Functions of Variable Numbers of...
7:15
Arduino and MATLAB: Reading Inputs and Writing Outputs
7:53
Performing Power System Studies, Part 3: Running Multiple...
2:46
Varargin and Nargin - Variable Inputs to a Function
2:27
How to Plot Multiple Lines on the Same Figure

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • 영업 담당 문의
  • 평가판 신청

MathWorks

Accelerating the pace of engineering and science

MathWorks는 엔지니어와 과학자들을 위한 테크니컬 컴퓨팅 소프트웨어 분야의 선도적인 개발업체입니다.

활용 분야 …

제품 소개

  • MATLAB
  • Simulink
  • 학생용 소프트웨어
  • 하드웨어 지원
  • File Exchange

다운로드 및 구매

  • 다운로드
  • 평가판 신청
  • 영업 상담
  • 가격 및 라이선스
  • MathWorks 스토어

사용 방법

  • 문서
  • 튜토리얼
  • 예제
  • 비디오 및 웨비나
  • 교육

지원

  • 설치 도움말
  • MATLAB Answers
  • 컨설팅
  • 라이선스 센터
  • 지원 문의

회사 정보

  • 채용
  • 뉴스 룸
  • 사회적 미션
  • 고객 사례
  • 회사 정보
  • Select a Web Site United States
  • 신뢰 센터
  • 등록 상표
  • 정보 취급 방침
  • 불법 복제 방지
  • 애플리케이션 상태
  • 매스웍스코리아 유한회사
  • 주소: 서울시 강남구 삼성동 테헤란로 521 파르나스타워 14층
  • 전화번호: 02-6006-5100
  • 대표자 : 이종민
  • 사업자 등록번호 : 120-86-60062

© 1994-2022 The MathWorks, Inc.

  • Naver
  • Facebook
  • Twitter
  • YouTube
  • LinkedIn
  • RSS

대화에 참여하기