Azzera filtri
Azzera filtri

Short question: Matrix with two arguments

3 visualizzazioni (ultimi 30 giorni)
Hi
I have seen the following syntax in some places:
[x y]
and was wondering what exactly it means? Something as:
[x y] = [1 5]
doesn't seem to work - so what exactly is this good for? Thanks a lot

Risposta accettata

José-Luis
José-Luis il 5 Gen 2013
Modificato: José-Luis il 5 Gen 2013
It can mean several things.
  • Output of a function:
[x y] = somefunction(arg1, arg2)
The function has two outputs, and one will be saved in x and the other in y
  • Concatenation
newVec = [x y];
The variables x and y are concatenated, provided they have the same size, and assigned to a new variable.
The brackets, however, cannot be used for multiple assignment as you did in your example. For more information look for "square brackets" in the documentation.
  2 Commenti
MiauMiau
MiauMiau il 5 Gen 2013
Thanks a lot, that really helped!
Matt J
Matt J il 5 Gen 2013
The brackets, however, cannot be used for multiple assignment as you did in your example.
To accomplish this, you would use DEAL,
>> [x,y]=deal(1,5)
x =
1
y =
5

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by