learning functions, need help

2 ビュー (過去 30 日間)
Andrew
Andrew 2014 年 9 月 19 日
コメント済み: Andrew 2014 年 9 月 19 日
How do i complete this task?
%MyFunction.m
function [out1, out2] = MyFunction(in1,in2)
Do calculations etc here
out1 = %Define out1 somewhere here
out2 = %Define out2 somewhere here
Use the function template described in the previous section to create a simple function called MyAdder() that can add two numbers or vectors together.
  1 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 9 月 19 日
Andrew - see the examples from declare function name, inputs, and outputs for details on how you would go about completing this assignment. Are you sure that there should be two outputs for your function (since you are just adding the inputs which will return one output), or is this just an example?

サインインしてコメントする。

回答 (1 件)

yonatan gerufi
yonatan gerufi 2014 年 9 月 19 日
編集済み: yonatan gerufi 2014 年 9 月 19 日
I highly recommend reading how functions works in Matlab.
for your question, this:
function [out1,out2] = MyAdder(a,b)
if (min(size(a)==size(b))==0)
out1= NaN;
out2=NaN;
else
out1 = a(1,:)+b(1,:);
out2 = a(1,:)+b(2,:);
end
good luck!
  1 件のコメント
Andrew
Andrew 2014 年 9 月 19 日
i will, thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by