return of function

2 ビュー (過去 30 日間)
huda nawaf
huda nawaf 2011 年 12 月 25 日
hi, I need two outputs from function , the first one is matrix , and the other is one value. two calls for function , the first call need the matrix and the second call need value. how do that? I built fun. with two outputs: function [m,n]=d(any input); thanks in advance
  1 件のコメント
Jan
Jan 2011 年 12 月 25 日
The question is not clear.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 12 月 26 日
Call the function twice and have the calling routine throw away the output that it does not need at the time.

Naz
Naz 2011 年 12 月 26 日
Let's say your function will have a name myFunction. As I understood, you want to pass a parameter to this function and get two output variables from it.
To call the function you use the following syntax:
[m,n]=myFunction(input);
To build your own function crate a file->new, paste this code and save as a separate file:
function [ M n ] = myFunction(inputParameter)
n=5*inputParameter;
M=ones(10,10);
end
The function will return matrix 'M' 10x10 of ones and 'n' will be your input scaled by 5.
  2 件のコメント
huda nawaf
huda nawaf 2011 年 12 月 26 日
thanks,
I got just M, what about n?
when I call this function from another program , how get n?
Walter Roberson
Walter Roberson 2011 年 12 月 26 日
In both places, call it as
[M, n] = myFunction(inputParameter);
and throw away which ever one of M or n you are not interested in at the time.
Your sentence about "two calls for function, the first call need the matrix and the second call need value" does indicate that there are two different calls, right?

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

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by