??? Undefined function or variable 'swap'.

回答(3 个)

Stephen23
Stephen23 2015-6-12
编辑:Stephen23 2015-6-12
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!
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)

类别

帮助中心File Exchange 中查找有关 Variables 的更多信息

标签

提问:

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