??? Undefined function or variable 'swap'.

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

답변 (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 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