??? Undefined function or variable 'swap'.

Antworten (3)

Stephen23
Stephen23 am 12 Jun. 2015
Bearbeitet: Stephen23 am 12 Jun. 2015

2 Stimmen

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 am 12 Jun. 2015

0 Stimmen

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 am 13 Jun. 2015

0 Stimmen

thank you it works perfectly

Kategorien

Mehr zu Variables finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 12 Jun. 2015

Beantwortet:

am 13 Jun. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by