??? Undefined function or variable 'swap'.

function [y,x]=swap(x,y)

1 件のコメント

ishan s
ishan s 2015 年 6 月 12 日
if anyone can guide me i would be thankful

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

回答 (3 件)

Stephen23
Stephen23 2015 年 6 月 12 日
編集済み: Stephen23 2015 年 6 月 12 日

2 投票

There is no need to write your own function: if you want to swap variables, then you can use the inbuilt deal function to do exactly this:
>> X = 3;
>> Y = 2;
>> [Y,X] = deal(X,Y)
Y =
3
X =
2
It even works for multiple arguments!
Walter Roberson
Walter Roberson 2015 年 6 月 12 日

0 投票

function [y,x]=swap(x,y)
end
is the entire code. To use it, for example,
a = 5; b = 48;
[a,b] = swap(a,b)
ishan s
ishan s 2015 年 6 月 13 日

0 投票

thank you it works perfectly

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

タグ

質問済み:

2015 年 6 月 12 日

回答済み:

2015 年 6 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by